简体   繁体   English

了解 where 子句与 join

[英]Understanding where clause vs join

Can somebody explain the difference between below query examples.有人可以解释以下查询示例之间的区别。

select column1,column2 
from table1 
join table2 
  on table1.columna = table2.columna 
  and columna='1234'

vs对比

select column1,column2 
from table1 
join table2 
  on table1.columna = table2.columna 
where columna='1234'

To answer the question in your comment, with the following tables:要回答您评论中的问题,请使用下表:

table1 and table21表 2

+---------+---------+    +---------+---------+ 
| column1 | columna |    | column2 | columna |
+---------+---------+    +---------+---------+
|      10 |    1234 |    |     100 |    1234 |
|      20 |    1234 |    |     200 |    5678 |
|      30 |    5678 |    +---------+---------+
|      40 |    9876 |
+---------+---------+

The inner join queries will produce:内部连接查询将产生:

+---------+---------+
| column1 | column2 |
+---------+---------+
|      10 |     100 |
|      20 |     100 |
+---------+---------+

An outer join query including the filter in the on clause will produce:on子句中包含过滤器的外连接查询将产生:

+---------+---------+
| column1 | column2 |
+---------+---------+
|      10 |     100 |
|      20 |     100 |
|      30 |         |
|      40 |         |
+---------+---------+

whereas an outer join query with the filter after the join will produce:而连接后带有过滤器的外连接查询将产生:

+---------+---------+
| column1 | column2 |
+---------+---------+
|      10 |     100 |
|      20 |     100 |
+---------+---------+

Note that since columna is in both tables, you have to indicate which columna the filter is associated to.请注意,由于columna在两个表中,您必须指明过滤器关联columna I assumed table1's.我假设table1的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM