我的表是:
tb_videos
id,
name
tb_video_tags
id,
video_id,
tag
我想通过标签选择视频及其相关视频。
答案 0 :(得分:0)
您可以尝试:
SELECT v.id, v.name, vr.id AS related_id, vr.name AS related_name
FROM tb_videos AS v
LEFT JOIN tb_video_tags AS vt
ON vt.video_id = v.id
LEFT JOIN tb_videos AS vr
ON vt.video_id = vr.id
AND v.id != vr.id
答案 1 :(得分:-1)
SELECT v.name
FROM tb_video_tags t, tb_video v
WHERE v.id = t.video_id
尝试并享受乐趣