连接SQL以从两个表中检索数据

时间:2021-03-03 15:22:37

There are two tables A and B. You are retreiving data from both tables where all rows from B table and only matching rows from A table should be displayed. Which of the following types of joins will you apply between A and B tables?

有两个表A和B。您正在从两个表中重新生成数据,其中所有来自B表的行和只显示来自表的匹配行。您将在A和B表之间应用以下类型的连接?

- Inner join
- Left outer join
- Right outer join
- Self join

4 个解决方案

#1


5  

Use left outer hoin or right outer join.

使用左外螺纹连接或右外螺纹连接。

For example, the following satisfy your requirement.

例如,以下内容满足您的需求。

select * from tableB
Left outer join tableA
on tableB.ID= tableA.ID

Or

select * from tableA
Right outer join tableB
on tableA.ID= tableB.ID

Better way to understand:

更好的方法来理解:

连接SQL以从两个表中检索数据

#2


1  

Easy, I would go with (B).

放松点,我选(B)。

SELECT * FROM B x
LEFT JOIN A y
  on x.someColName = y.someColname

EDIT: can also use Right join

编辑:也可以使用右连接。

SELECT * FROM A x
RIGHT OUTER JOIN B y
  on x.someColName = y.someColname

#3


0  

This looks like homework, but it's dead simple enough that I'll just say that you're asking for B LEFT JOIN A.

这看起来像家庭作业,但它非常简单,我只说你要求B左加入A。

#4


0  

Join Left

加入了

http://www.w3schools.com/Sql/sql_join_left.asp

http://www.w3schools.com/Sql/sql_join_left.asp

#1


5  

Use left outer hoin or right outer join.

使用左外螺纹连接或右外螺纹连接。

For example, the following satisfy your requirement.

例如,以下内容满足您的需求。

select * from tableB
Left outer join tableA
on tableB.ID= tableA.ID

Or

select * from tableA
Right outer join tableB
on tableA.ID= tableB.ID

Better way to understand:

更好的方法来理解:

连接SQL以从两个表中检索数据

#2


1  

Easy, I would go with (B).

放松点,我选(B)。

SELECT * FROM B x
LEFT JOIN A y
  on x.someColName = y.someColname

EDIT: can also use Right join

编辑:也可以使用右连接。

SELECT * FROM A x
RIGHT OUTER JOIN B y
  on x.someColName = y.someColname

#3


0  

This looks like homework, but it's dead simple enough that I'll just say that you're asking for B LEFT JOIN A.

这看起来像家庭作业,但它非常简单,我只说你要求B左加入A。

#4


0  

Join Left

加入了

http://www.w3schools.com/Sql/sql_join_left.asp

http://www.w3schools.com/Sql/sql_join_left.asp