Query gives not the right records with WHERE

36 Views Asked by At

I have a little problem. This query gives also records where the field 'active' is 0. I tought the problem was something with the brackets, but i can't find out how it should be.

Anyone an idea?

SELECT id, title, message_short, date_posted, posterID, active, deleted 
FROM articles
WHERE title LIKE '%blah%' OR
      message LIKE '%blah%' AND
      deleted = 0 AND
      active = 1
ORDER BY date_posted DESC
1

There are 1 best solutions below

2
Kiran On

try this

 SELECT id, title,message_short,date_posted,posterID,active,deleted FROM 
 articles WHERE (title LIKE '%blah%' OR message LIKE '%blah%')
 AND deleted=0 AND active=1 ORDER BY date_posted DESC