mysql 表关联时执行顺序

left join  左连接

mysql 表关联时执行顺序
 1 with temp1 as (
 2 select 1 as id ,12 as num union 
 3 select 2 as id ,13 as num union 
 4 select 3 as id ,12 as num union 
 5 select 4 as id ,14 as num union 
 6 select 5 as id ,12 as num union 
 7 select 6 as id ,16 as num  
 8 ), temp2 as (
 9 select 1 as id ,a as var union 
10 select 2 as id ,b as var union 
11 select 3 as id ,c as var union 
12 select 4 as id ,a as var union 
13 select 5 as id ,b as var union 
14 select 6 as id ,f as var  
15 )
16 select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id
View Code

mysql 表关联时执行顺序

 

left join  左连接 (on 中加条件)

说明:先关联, 再过滤 ;

mysql 表关联时执行顺序
 1 with temp1 as (
 2 select 1 as id ,12 as num union 
 3 select 2 as id ,13 as num union 
 4 select 3 as id ,12 as num union 
 5 select 4 as id ,14 as num union 
 6 select 5 as id ,12 as num union 
 7 select 6 as id ,16 as num  
 8 ), temp2 as (
 9 select 1 as id ,a as var union 
10 select 2 as id ,b as var union 
11 select 3 as id ,c as var union 
12 select 4 as id ,a as var union 
13 select 5 as id ,b as var union 
14 select 6 as id ,f as var  
15 )
16 -- select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id
17 select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id and t1.num=12 
18 -- select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id where t1.num=12
View Code

mysql 表关联时执行顺序

left join  左连接  (末尾 where 条件)

说明:最后过滤

mysql 表关联时执行顺序
 1 with temp1 as (
 2 select 1 as id ,12 as num union 
 3 select 2 as id ,13 as num union 
 4 select 3 as id ,12 as num union 
 5 select 4 as id ,14 as num union 
 6 select 5 as id ,12 as num union 
 7 select 6 as id ,16 as num  
 8 ), temp2 as (
 9 select 1 as id ,a as var union 
10 select 2 as id ,b as var union 
11 select 3 as id ,c as var union 
12 select 4 as id ,a as var union 
13 select 5 as id ,b as var union 
14 select 6 as id ,f as var  
15 )
16 -- select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id
17 -- select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id and t1.num=12 
18 select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id where t1.num=12
View Code

mysql 表关联时执行顺序

 

left join  左连接  ( on 中加条件 & 末尾 where 条件)

mysql 表关联时执行顺序
 1 with temp1 as (
 2 select 1 as id ,12 as num union 
 3 select 2 as id ,13 as num union 
 4 select 3 as id ,12 as num union 
 5 select 4 as id ,14 as num union 
 6 select 5 as id ,12 as num union 
 7 select 6 as id ,16 as num  
 8 ), temp2 as (
 9 select 1 as id ,a as var union 
10 select 2 as id ,b as var union 
11 select 3 as id ,c as var union 
12 select 4 as id ,a as var union 
13 select 5 as id ,b as var union 
14 select 6 as id ,f as var  
15 )
16 select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id and t1.num=12  where  t1.num=12
View Code

mysql 表关联时执行顺序

 

mysql 表关联时执行顺序

上一篇:一个有趣的问题, 你知道SqlDataAdapter中的Fill是怎么实现的吗


下一篇:sql sever 常见游标写法,及如何强制停止