我花了一些时间试图让这个工作用SELECT CASE,但我失败了......(感谢给我使用COLASCE()现在)MYSQL LEFT JOIN优化与CASE
我如何能优化这个SELECT通过使用CASE/IF语句?这是从字段选择的不同表格快速查询的方式吗?
SELECT a.folderid, a.foldername, a.contenttype, COALESCE(b.descriptor, c.descriptor, d.descriptor, e.descriptor, f.descriptor) as descriptor
FROM t_folders a
LEFT JOIN t_files b
ON a.contenttype = 'file' AND a.contentid = b.fileid
LEFT JOIN t_links c
ON a.contenttype = 'link' AND a.contentid = c.linkid
LEFT JOIN t_extfiles d
ON a.contenttype = 'extfile' AND a.contentid = d.extfileid
LEFT JOIN t_videos e
ON a.contenttype = 'video' AND a.contentid = e.videoid
LEFT JOIN t_exams f
ON a.contenttype = 'exam' AND a.contentid = f.examid
WHERE a.folderid = $folderId
ORDER BY a.folderid DESC
你想达到什么目的?为什么使用CASE或IF?你想优化什么?你明白什么是联盟?如果是的话,为什么它不是你要找的? – fancyPants 2012-03-17 13:43:34
我想知道是否有可能替换这些LEFT JOINs CASE/IF。它可以更快的MySQL? – kbitdn 2012-03-18 11:39:02
@tombom和kbitdn:我没有这个问题的答案,但我也会对它感兴趣...我也有类似的问题... – Chris 2012-03-28 12:11:28