Issue
How would I take text that is a \n delimited string and output every row that contains a certain substring?
For example:
DB:
product | keywords
-------------------
test | test\ntest1\ntest2\ntest3
test1 | test\nblah\nblah
test2 | tst\nblah\nblah
test3 | testr\nblah\nblah
SELECT * FROM products WHERE
How would I write the WHERE clause to pull product test and test1?
Solution
This should work
select * from your_table
where find_in_set('test', replace(keywords, '\n', ',')) > 0
or find_in_set('test1', replace(keywords, '\n', ',')) > 0
But actually you will be better off by changing the table design and don’t store multiple values in a single colum.
Answered By – juergen d
Answer Checked By – Mildred Charles (BugsFixing Admin)