我的视频表包含列(username,userId,...)和带有列的用户表(username,userId,explicitContent,...)。
explicitContent列的成人内容值为1,一般内容的值为0。
我试过了:
SELECT *
FROM video
RIGHT JOIN users ON users.explicitContent = 0
WHERE hashtags LIKE 'cats'
ORDER BY created DESC
如何选择explcitContent = 0的视频?
谢谢!
答案 0 :(得分:0)
Join用于使用用户的主键和视频的外键将表连接在一起。但是,您需要在sers.explicitContent = 0
之后添加条件where
。
SELECT *
FROM video
INNER JOIN users ON users.userid = video.userid
WHERE hashtags LIKE 'cats' AND
users.explicitContent = 0
ORDER BY created DESC
答案 1 :(得分:0)
您需要加入userid
字段。不需要外连接:
SELECT v.*
FROM video v inner join
users u
ON v.userid = u.userid and
u.explicitContent = 0
WHERE hashtags LIKE 'cats'
ORDER BY created DESC