Hi,
I am trying to filter all oak living room furniture. Current I can only filter oak coffee tables. But I am stuck on how to filter oak coffee tables and oak sideboards.
Can anyone advise how I can filter but always using one keyword?
This displays all oak coffee tables.
WHERE linkname LIKE '%oak%' and linkname LIKE '%coffee%'";
This is displays nothing
WHERE linkname LIKE '%oak%' and linkname LIKE '%coffee%' and linkname LIKE '%sideboard%'";
This displays all oak coffee tables and all sideboards of any material.
WHERE linkname LIKE '%oak%' and linkname LIKE '%coffee%' or linkname LIKE '%sideboard%'";
MySQL interprets the conditions from left to right, so it reads that last query as:
WHERE (linkname LIKE '%oak%' AND linkname LIKE '%coffee%') OR linkname LIKE '%sideboard%';
You can change how the conditions are evalutated by using parenthesis, like this:
WHERE linkname LIKE '%oak%' AND (linkname LIKE '%coffee%' OR linkname LIKE '%sideboard%');
Your second ex precludes the result you desire simply because of bad logic. If item A is ‘oak coffee tables’ and item B is ‘oak sideboard’ then how you you query for ‘oak’ and ‘coffee’ and ‘sideboard’?
where linkname like ‘%oak%’ and (linkname like ‘$coffee%’ or linkname like ‘%sideboard%’)
Hi,
I tried the following but it displays all oak. Should I be doing it like this?
WHERE linkname LIKE '%oak%' and (linkname like '$coffee%' or linkname like '%sideboard%')";
Sorry - I typed a $ in place of a % and you did a cut/paste. Correct and re-try.