我有两个查询来获取相同的数据,它们或多或少具有相同的执行时间。
SELECT name AS prog_name,d.chap_name,d.vid_name,d.idvideo FROM program
JOIN (SELECT name AS chap_name,chapter.idprogram, c.vid_name,c.idvideo FROM chapter
JOIN (SELECT a.name AS vid_name, a.idvideo, b.idchapter FROM video a
JOIN (SELECT idvideo,idchapter,x.idchaptervideo FROM chaptervideo
JOIN (SELECT idchaptervideo FROM prescriptionvideo WHERE idprescription=50)x
ON x.idchaptervideo=chaptervideo.idchaptervideo) b
ON b.idvideo=a.idvideo)c
ON c.idchapter=chapter.idchapter) d
ON d.idprogram=program.idprogram
SELECT program.name AS prog_name,chapter.name as chap_name,video.name as vid_name,video.idvideo FROM prescriptionvideo
JOIN chaptervideo ON prescriptionvideo.idchaptervideo=chaptervideo.idchaptervideo
JOIN video on chaptervideo.idvideo=video.idvideo
JOIN chapter on chaptervideo.idchapter=chapter.idchapter
JOIN program on chapter.idprogram=program.idprogram
where idprescription=50
有人可以指导我其中哪一个更好。我在前者的加入之前和后者的加入之后使用了过滤。MySQL 解释显示,与后者相比,前者的行扫描更多。