首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

两种SQL查询哪个效率高点?解决方案

2012-02-10 
两种SQL查询哪个效率高点????1.组合表查询selecta.*fromtest1atest2bwherea.columeb.columeand...2.复合

两种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 ...)子查询返回的结果是唯一的!

热点排行