Let's start by looking at the results of the left join and the right join and the Inner join and the full join working on the table.
- Create a new two table in the database and insert the data you want to test.
New table:
[SQL]View PlainCopy
Use [Test]
GO
/****** object: Table [dbo].[ EMP] Script Date: 06/22/2012 15:37:28 ******/
SET ansi_nulls on
GO
SET quoted_identifier on
GO
CREATE TABLE [dbo].[ EMP] (
[Ename] [nchar] (Ten) COLLATE chinese_prc_ci_as not NULL,
[City] [nchar] (Ten) COLLATE chinese_prc_ci_as NULL
) on [PRIMARY]
[SQL]View PlainCopyUse [Test]
GO
/****** object: Table [dbo].[ SAL] Script Date: 06/22/2012 15:38:04 ******/
SET ansi_nulls on
GO
SET quoted_identifier on
GO
CREATE TABLE [dbo].[ SAL] (
[Ename] [nchar] (Ten) COLLATE chinese_prc_ci_as not NULL,
[SALARY] [Money] NULL
) on [PRIMARY]
Table to insert data from:
EMP Table:
Sal table:
- Left JOIN connect [SQL] view plain copy
- SELECT * FROM EMP left join SAL on EMP. ename = SAL. ename;
Left JOIN, the table EMP is the primary table, so the query results show all the information of the EMP (primary table) and the SAL (schedule) information related to EMP.
- Right connect [SQL] view plain copy
- Select * from EMP right join SAL on EMP. ename = SAL. ename;
Right connection, table Sal is the primary table, so the query results show all the information of the salt (the primary table) and the EMP (schedule) and the information that Sal wants to close.
- Internal connection [SQL] view plain copy
- SELECT * FROM EMP inner join SAL on EMP. ename = SAL. ename;
Link, which displays information related to a table.
- Full connection [SQL] view plain copy
- SELECT * from EMP full join SAL on EMP. ename = SAL. ename;
Fully connected, displaying all two tables of information.
The difference between left join and right join in SQL and Inner join vs. Full join