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