Take a look at the results of the left join and the right join with the Inner join and the full join to manipulate 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 PlainCopy
- Use [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 connection [SQL] view plain copy
- select * from emp left join sal on emp. Ename = sal. ename;
Left connection, table EMP is the main table, So the result of the query is to display all the information of the EMP (main table) and the SAL (schedule) information related to the 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 MySQL and Inner join and full join