Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

select from table with one mandatory condition and tow optional conditions

am trying to make an advanced search form for my site and I want to get only rows with uploaded videos links and check if the title and description is equal to the search query
I tried :

SELECT `id` 
FROM `posts` 
WHERE `file` LIKE '%video%' 
AND `title` LIKE '%{$search_query}%' 
OR `description` LIKE '%{$search_query}%';

But in this case, MySQL returns all the rows that contain the search query in their description or title regardless of whether the ‘file’ column contains "video" or not and I want it to return only matches with video files how can I achieve that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You skipped parentheses

SELECT `id` 
  FROM `posts` 
 WHERE `file` LIKE '%video%' 
   AND (`title` LIKE '%{$search_query}%' 
    OR `description` LIKE '%{$search_query}%');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading