Edited at

多対多テーブルでMySQLでLEFT JOINして中身確認の備忘録

More than 5 years have passed since last update.

ちょっと長いけどこんな感じです

videos基準

select videos.id, videos.title, tags.id, tags.name from videos left join tags_videos on videos.id=tags_videos.video_id left join tags on tags_videos.tag_id=tags.id;

tags基準

select videos.id, videos.title, tags.id, tags.name from tags left join tags_videos on tags.id=tags_videos.tag_id left join videos on tags_videos.video_id=videos.id;