关于使用外连接所需的帮助 [英] help needed regarding the use of outer joins

查看:97
本文介绍了关于使用外连接所需的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我使用外连接asn我们如何在querry中应用它们

解决方案

你需要了解SQL JOINS。



这里:

W3Schools:SQL Joins [ ^ ]

< a href =http://www.sql-tutorial.net/SQL-JOIN.asp> SQL教程 - SQL连接 [ ^ ]

CP:SQL加入 [ ^ ]

MSDN:加入基础知识 [< a href =http://msdn.microsoft.com/en-us/library/ms191517.aspxtarget =_ blanktitle =新窗口> ^ ]


使用外部联接 [ ^ ]

它返回 FROM 子句中提到的至少一个表或视图中的所有行,只要这些行符合任何 WHERE或HAVING 搜索条件。

从左外部联接引用的左表中检索所有行,右外部联接中引用右表中的所有行



两个表中的所有行都以完整的外部联接方式返回。



在哪里使用外连接? [ ^ ]

什么是SQL OUTER JOIN [ ^ ]


外部联接主要可以被认为是两种类型 - 左外连接和右外连接。



当你想要第一个表中的所有行和第二个表中的连接行时,使用左外连接。



当你想要所有行时,使用右外连接在第二个表格和第一个表格中的连接行。



假设您有两张桌子



表A

 Id名称
1 A
2 B
3 C





表B

 Id名称排名
1 B 1
2 D 2
3 E 3



如果您使用像

这样的查询在这些表上使用left outer,请选择A .Name,B.Rank from table1 A left = B.Name 



你的输出将是 -

姓名等级
A
B 2
C





只有排名返回了B,但第一个表的行仍然返回。


can any one tell me the use of outer join asn how we apply them in querry

解决方案

You need to read about SQL JOINS.

Here:
W3Schools: SQL Joins[^]
SQL Tutorial - SQL Joins[^]
CP: SQL Joins[^]
MSDN: Joins Fundamentals[^]


Using Outer Joins[^]
It return all rows from at least one of the tables or views mentioned in the FROM clause, as long as those rows meet any WHERE or HAVING search conditions.
All rows are retrieved from the left table referenced with a left outer join, and all rows from the right table referenced in a right outer join.

All rows from both tables are returned in a full outer join.

Where to use outer joins?[^]
What is SQL OUTER JOIN[^]


Outer Joins can primarily be considered to be of two types - left and right outer joins.

A left outer join is used when you want all rows in the first table and joined rows from the second table.

A right outer join is used when you want all rows in the second table and joined rows from the first table.

Lets say you have two tables

Table A

Id  Name
1   A
2   B
3   C



Table B

Id  Name  Rank
1   B     1
2   D     2
3   E     3


If you use left outer on these tables by using a query like

select A.Name, B.Rank from table1 A left join table B on A.Name = B.Name


your output would be -

Name Rank
A      
B      2
C



Only the rank for B was returned, however rows for the first table were still returned.


这篇关于关于使用外连接所需的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆