1

我正在尝试检查用户是否观看了视频。我有两张表 - 一张填充了观看视频的视频 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 函数上定位多个条件?

提前致谢-

4

1 回答 1

4

你可以这样做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

于 2013-02-04T17:45:58.923 回答