MySQL in with Like

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



Leave a reply



Submit