3

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.

2 Answers 2

4

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';
Sign up to request clarification or add additional context in comments.

Comments

3

Try:

SELECT * 
FROM customers 
WHERE for LIKE '%AMC PHD & WWS%'
    or for LIKE '%Rostfrei%'
    or for LIKE '%Thermopac%'

1 Comment

it seems to be working.. but is there any way so that I don't have to write field name again and again..?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.