在SQL中联接多个表

编程入门 行业动态 更新时间:2024-10-10 03:22:24
本文介绍了在SQL中联接多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人可以向我介绍有关加入的信息吗?

Can sombody Explains me about joins?

内部联接根据条件选择公共数据.

Inner join selects common data based on where condition.

左外部联接从左选择所有数据,而与公共无关,但从右表获取公共数据,反之亦然.

Left outer join selects all data from left irrespective of common but takes common data from right table and vice versa for Right outer.

我知道基本知识,但是对于5、8、10个表进行联接时,问题仍然存在.

I know the basics but question stays when it comes to join for than 5, 8, 10 tables.

假设我要加入10个表.如果我对前5个表进行了内部联接,现在尝试对第6个表进行左联接,那么查询将如何工作?

Suppose I have 10 tables to join. If I have inner join with the first 5 tables and now try to apply a left join with the 6th table, now how the query will work?

我的意思是说现在前5个表的结果集将被视为左表,而第6个表的结果集将被视为右表?还是只将第五张表视为左表,将第六张表视为右表?请为此提供帮助.

I mean to say now the result set of first 5 tables will be taken as left table and the 6th one will be considerded as Right table? Or only Fifth table will be considered as left and 6th as right? Please help me regarding this.

推荐答案

在联接多个表时,每个联接的输出在逻辑上形成一个虚拟表,该虚拟表将进入下一个联接.

When joining multiple tables the output of each join logically forms a virtual table that goes into the next join.

因此,在您所提问的示例中,连接前5个表的综合结果将被视为左侧表.

So in the example in your question the composite result of joining the first 5 tables would be treated as the left hand table.

有关更多信息,请参见 Itzik Ben-Gan的逻辑查询处理海报对这个.

See Itzik Ben-Gan's Logical Query Processing Poster for more about this.

可以通过放置ON子句来控制联接中涉及的虚拟表.例如

The virtual tables involved in the joins can be controlled by positioning the ON clause. For example

SELECT * FROM T1 INNER JOIN T2 ON T2.C = T1.C INNER JOIN T3 LEFT JOIN T4 ON T4.C = T3.C ON T3.C = T2.C

等同于(T1 Inner Join T2) Inner Join (T3 Left Join T4)

更多推荐

在SQL中联接多个表

本文发布于:2023-10-28 10:47:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536416.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!