MySQL Query with multiple AND statements seems to be ignoring one

后端 未结 5 1506
花落未央
花落未央 2020-12-20 00:25

I\'m trying to run a query on a MySQL database, but I found that it seems to be ignoring the \'status\' item.

SELECT * FROM  `posts`  
WHERE
      `tags` LIK         


        
5条回答
  •  借酒劲吻你
    2020-12-20 01:13

    Try to use brackets to emphasize your logical sentences. Such as:

    SELECT *  
      FROM  `posts`  
     WHERE  (`tags` LIKE  '%gda%' OR  `tags` LIKE  '%contests%' OR  `tags` LIKE  '%merch%') 
       AND  `newsID` !=  '2134' 
       AND `status` > '1' 
    ORDER BY  `postDate` DESC  LIMIT 5
    

    Otherwise, your logic gets lost. Also using brackets makes easier to read your SQL sentences.

提交回复
热议问题