mysql查询给出错误

时间:2015-03-14 10:41:40

标签: php mysql

SELECT * 
   FROM rss_cron_data 
  WHERE 
    ((title LIKE '%sp100%' OR description LIKE '%sp100%')
    (title LIKE '%DEX%' OR description LIKE '%DEX%')
    (title LIKE '%NET%' OR description LIKE '%NET%')) 
    AND `pubDate` BETWEEN '2015-03-07 11:35:53' and '2015-03-14 11:35:53' 
ORDER BY `pubDate` desc

这是mysql查询及其给出错误

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近'(标题LIKE'%DE​​X%' OR description LIKE'%DE​​X%')(标题为LIKE   '%NET%'或描述'在第3行

这个查询中有什么不对,任何人都可以解释一下......提前谢谢

2 个答案:

答案 0 :(得分:2)

您缺少两种情况之间的逻辑条件。像

一样改变你的状况
((title LIKE '%sp100%' OR description LIKE '%sp100%') AND 
(title LIKE '%DEX%'  OR description LIKE '%DEX%') AND
(title LIKE '%NET%'  OR description LIKE '%NET%'))

答案 1 :(得分:0)

使用和/或在您的条件之间

SELECT * FROM (`rss_cron_data`) WHERE 
    ((title LIKE '%sp100%' OR description LIKE '%sp100%')
    (title LIKE '%DEX%' OR description LIKE '%DEX%')
    (title LIKE '%NET%' OR description LIKE '%NET%')) 
    AND `pubDate` BETWEEN '2015-03-07 11:35:53' and '2015-03-14 11:35:53' 
ORDER BY `pubDate` desc

更改为

SELECT * FROM (`rss_cron_data`) WHERE 
    ((title LIKE '%sp100%' OR description LIKE '%sp100%') or 
    (title LIKE '%DEX%' OR description LIKE '%DEX%') or 
    (title LIKE '%NET%' OR description LIKE '%NET%')) 
    AND `pubDate` BETWEEN '2015-03-07 11:35:53' and '2015-03-14 11:35:53' 
ORDER BY `pubDate` desc