MySQL LIKE IN()?
A REGEXP might be more efficient, but you'd have to benchmark it to be sure, e.g.
SELECT * from fiberbox where field REGEXP '1740|1938|1940';
MySQL IN with LIKE
You can use a number of LIKE expressions:
SELECT fields
FROM table
WHERE age = "50"
AND (
name LIKE "2010-09-17%"
OR name LIKE "2010-09-16%"
);
or you can use a regex:
SELECT fields
FROM table
WHERE age = "50"
AND name REGEXP "2010-09-17.*|2010-09-16.*";
or, cleverly
SELECT fields
FROM table
WHERE age = "50"
AND name REGEXP "2010-09-1(6|7).*";
MySQL like with IN clause
That is bad database design. But you can use REGEXP
instead:
WHERE permission.PERMISSION_ID REGEXP '_(123|456|789)_'
It is still bad database design.
MySQL Using LIKE, AND, OR together
Group your OR
condition with parenthesis.
SELECT *
FROM Pictures
WHERE (ImageTitle LIKE '%yaa%'
OR ImageDescription LIKE '%yaa%')
AND Approval='Approved'
Order BY DateTime DESC
mysql like string which contains %
Try \%:
SELECT *
FROM `customer`
WHERE `emailcampaign` LIKE '%solgar -51\%'
MySQL Like multiple values
The (a,b,c)
list only works with in
. For like
, you have to use or
:
WHERE interests LIKE '%sports%' OR interests LIKE '%pub%'
mysql SELECT where like and like
In MySQL, you can use find_in_set()
:
select *
from products
where find_in_set('3', papers) and find_in_set('4', papers) and find_in_set('5', papers)
Note that your question suggests a flawed database design. You should not be storing multiple integer values in a single string column. Instead, you should have each integer value in a separate row, probably in another table, that would refer to the main table through a foreign key constraint. Recommended reading: Is storing a delimited list in a database column really that bad?.
MySQL LIKE Operator with Special Characters Confusion
Maybe this help you understand the usage of escape chars in mySQL
https://stackoverflow.com/a/27061961/634698
Related Topics
Dynamic Column in Select Statement Postgres
Different Ways to Alias a Column
Query to Return 1 Instance of a Record with Duplicates
Oracle - Select Count on a Subquery
Displaying Zero Valued Months with SQL
How to Partition Postgres Table Using Intermediate Table
Problem with Alter Then Update in Try Catch with Tran Using Transact-Sql
Dynamic Table Name in Select Statement
How to Replace Multiple Characters in Access SQL
Mod Negative Numbers in SQL Just Like Excel
Creating a Flattened Table/View of a Hierarchically-Defined Set of Data
How to Get SQL to Generate Both the Starting and Ending Xml Tags
How to Get Specific Xml Namespace in Xquery in SQL Server