开发者

Exclude result from query

开发者 https://www.devze.com 2023-03-30 12:52 出处:网络
I have a that takes the tags of a current video and matches them with other videos for results. The only issue is I would like to exclude the video that the tags are from开发者_如何转开发 (exclude a s

I have a that takes the tags of a current video and matches them with other videos for results. The only issue is I would like to exclude the video that the tags are from开发者_如何转开发 (exclude a specific vid_id). I tried the following but the line AND vid_id!=some_id breaks it. Any ideas?

$sql = "SELECT video.*,COUNT(*) as count FROM tags LEFT JOIN video 
ON (tags.vid_id = video.vid_id) 
WHERE name IN(?,?) AND vid_id!=some_id 
GROUP BY vid_id ORDER BY count DESC LIMIT 5";


  1. Did you forget to close the parenthesis after the ON clause?

  2. Also, since your vid_id column is present both in the video table and in the tags table, you'll need to specify the tablename in the WHERE-clause (yes, even though the ON-statement requires they be equal)

That gives:

$sql = "SELECT video.*,COUNT(*) as count 
FROM tags 
LEFT JOIN video 
ON (tags.vid_id = video.vid_id)
WHERE name IN(?,?) 
AND video.vid_id != some_id 
ORDER BY count DESC 
LIMIT 5";
0

精彩评论

暂无评论...
验证码 换一张
取 消