内连接查询 (select * from a join b on a.id = b.id) 与 关联查询 (select * from a , b where a.id = b.id)的区别

转自https://blog.csdn.net/l690781365/article/details/76261093

1.首先了解 on 、where 的执行顺序以及效率?

from a join b 与 from a, b 产生的临时表结果集 都是执行笛卡尔积即(select * from a cross join b )两表的行乘积数。

on :与取得结果集同步进行数据刷选及过滤

where : 获得结果集之后,才进行数据刷选及过滤

执行顺序:on在上游,where在中游,having在下游。

案例:1.select * from test_text tx left outer join  test_test ts on tx.id =ts.tid; 执行结果:

2.select * from test_text tx left outer join  test_test ts on tx.id =ts.tid  where tx.id =ts.tid; 结果集如下:


3.select * from test_text tx left outer join  test_test ts on tx.id =ts.tid  where tx.id =ts.tid having tx.id =5;

posted on 2018-05-07 11:39  lijingran  阅读(14406)  评论(0编辑  收藏

导航