以下查询仍会返回值10643,即使它在NOT IN条件中具体列出。
SELECT
`media` . `id`
FROM
`media`
LEFT JOIN
`categories` ON `categories`.`id` = `media`.`category_id`
JOIN
`users` ON `users`.`id` = `media`.`author`
WHERE
`media`.`public` =1
AND
`media`.`date_posted` <= (SELECT CONVERT_TZ(now(),'US/Pacific','US/Eastern'))
AND
`media`.`date_posted` > DATE_SUB((SELECT CONVERT_TZ(now(),'US/Pacific','US/Eastern')) , INTERVAL 25 DAY )
AND
`media`.`id` NOT IN ('10659,10656,10655,10654,10653,10652,10651,10650,10649,10648,10646,10647,10645,10644,10643')
ORDER BY
`media`.`views` DESC
LIMIT 15
表格
分类 id |类
媒体 id |类型| category_id |标题|副标题|作者|图片|内容|公众| date_posted |视图
用户 id |名字|名字
答案 0 :(得分:3)
NOT IN()的语法不正确。你给它一个字符串,改为这样做:
SELECT
`media` . `id`
FROM
`media`
LEFT JOIN
`categories` ON `categories`.`id` = `media`.`category_id`
JOIN
`users` ON `users`.`id` = `media`.`author`
WHERE
`media`.`public` =1
AND
`media`.`date_posted` <= (SELECT CONVERT_TZ(now(),'US/Pacific','US/Eastern'))
AND
`media`.`date_posted` > DATE_SUB((SELECT CONVERT_TZ(now(),'US/Pacific','US/Eastern')) , INTERVAL 25 DAY )
AND
`media`.`id` NOT IN ('10659', '10656' , '10655', '10654', '10653', '10652', '10651', '10650', '10649', '10648', '10646', '10647', '10645', '10644', '10643')
ORDER BY
`media`.`views` DESC
LIMIT 15
答案 1 :(得分:1)
你有数字左右的引文 试试NOT IN(10659,10660 ......)