请教SQL查询效率比较
这两句SQL查询结果一致:
请问那句性能更好?效率更高?
a表和b表的关系为一对多, 谢谢!
(1) Select Distinct id,name from a join b on a.id=b.id where b.id=10
(2) Select id,name from a where exists (select id from b where a.id=b.id and b.id=10)
问题点数:20、回复次数:3Top
1 楼zjcxc(邹建)回复于 2006-03-03 20:45:24 得分 20
一般是B的效率高.
A要多做distinct的处理
另, id 列的来源不明Top
2 楼wintersunair(旋律游魂)回复于 2006-03-03 20:54:48 得分 0
谢谢邹老师,我买过您写的书,我写漏了,对,就是
(1) Select Distinct a.id,a.name from a join b on a.id=b.id where b.id=10
(2) Select a.id,a.name from a where exists (select id from b where a.id=b.id and b.id=10)
Top
3 楼ZengMuAnSha(曾牧暗鲨)回复于 2006-03-04 09:01:44 得分 0
如果數據量超大的話 第二個快 否則第一個快 你可以在查詢分析器裡打開查詢分析 看看執行計劃Top




