日期:2014-05-20  浏览次数:20582 次

两种SQL查询哪个效率高点????
1.组合表查询
select   a.*   from   test1   a   test2   b   where   a.colume   =   b.colume   and   ...

2.复合查询
select   a.*   from   test1   a   where   a.colume   =   (select   b.colume   from   test2   b   where   ...)

假定两条语句都能正确执行!!!!

------解决方案--------------------
应该是1吧~~
我瞎说的不要理我~~
------解决方案--------------------
要不弄点大数据量,试试?
我也是瞎说的不要理我~~
------解决方案--------------------
是1, 2的效率及其低下的。 从复杂度而言 1的复杂度如果是X 2的复杂度是X的一个笛卡儿乘积
------解决方案--------------------
假定两条语句都能正确执行,那么,第二条的效率高!

理由:
如果select a.* from test1 a where a.colume = (select b.colume from test2 b where ...)能正确执行,说明(select b.colume from test2 b where ...)子查询返回的结果是唯一的!
------解决方案--------------------
楼主的第2条其实应该是
select a.* from test1 a where a.colume in (select b.colume from test2 b where ...)
这样的话第一条肯定效率高
------解决方案--------------------
假定两条语句都能正确执行,那么,第二条的效率高!

理由:
如果select a.* from test1 a where a.colume = (select b.colume from test2 b where ...)能正确执行,说明(select b.colume from test2 b where ...)子查询返回的结果是唯一的!
-------------------
支持
------解决方案--------------------
1的效率要高
------解决方案--------------------

------解决方案--------------------
2的效率高,同意.....
------解决方案--------------------
2的效率高,同意楼上的。
理由:
如果select a.* from test1 a where a.colume = (select b.colume from test2 b where ...)能正确执行,说明(select b.colume from test2 b where ...)子查询返回的结果是唯一的!