我正在检查用户是否观看了视频。我有两个表-一个是视频id和观看视频的用户id。另一个有录像。

SELECT *
FROM videos
WHERE Channel LIKE '%$finalmood%'
AND WHERE NOT IN(select * from userviews
    where userviews.videoid = videos.id
    where userviews.userid = $tempuser

我想我可能是不正确地使用了notin函数。如何在notin函数上定位多个条件?
提前谢谢-

最佳答案

你可以用一个LEFT JOIN

SELECT *
FROM videos
LEFT JOIN userviews ON userviews.videoid = videos.id AND userviews.userid = $tempuser
WHERE Channel LIKE '%$finalmood%' AND userviews.videoid IS NULL

顺便说一句,一定要消毒$tempuser

09-27 13:14