Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mysql query issue

Tags:

sql

mysql

here's my table:

enter image description here

and I want get the customers which have some values of for/category fields which is comma separated..

I am trying something like this:

SELECT * FROM `customers` WHERE `for` LIKE ('%AMC PHD & WWS%' OR '%Rostfrei%' OR '%Thermopac%')

but its giving empty result.

like image 879
Vaibhav Gupta Avatar asked Jul 16 '26 06:07

Vaibhav Gupta


1 Answers

RedFilter's SQL is correct, but you should also know that "for" is a MySQL reserved word. You should avoid using it as a column name, or wrap it in backticks when you use it:

SELECT * 
FROM customers 
WHERE `for` LIKE '%AMC PHD & WWS%'
    OR `for` LIKE '%Rostfrei%'
    OR `for` LIKE '%Thermopac%';

The alternative, typing the column name once is:

SELECT * FROM customers WHERE `for` REGEXP 'AMC PHD \& WWS|Rostfrei|Thermopac';
like image 72
dtbarne Avatar answered Jul 19 '26 01:07

dtbarne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!