--preparatory work
drop table if exists Emp;
CREATE table if not exists EMP
(
UID INT primary KEY,
Sid int
);
INSERT into EMP values (+);
INSERT into EMP values (2,2);
drop table if exists Sal;
CREATE table if not exists Sal
(
Sid Int Primary KEY,
Salary float
);
INSERT into Sal values (1,11);
INSERT into Sal values (3,33);
--View Results
SELECT * from EMP LEFT join Sal on emp.sid = Sal.sid;
The left table is the main (the left table content appears at least once)
Uid |
Sid |
Sid |
Salary |
1 |
1 |
1 |
11 |
2 |
2 |
Null |
Null |
SELECT * from EMP right join Sal on emp.sid = Sal.sid;
The right table is the main (the right table content appears at least once)
Uid |
Sid |
Sid |
Salary |
1 |
1 |
1 |
11 |
Null |
Null |
3 |
33 |
SELECT * FROM EMP inner join Sal on emp.sid = Sal.sid;
The equivalent of the above two tables to find the intersection
Uid |
Sid |
Sid |
Salary |
1 |
1 |
1 |
11 |
MySQL left Join,right Join,inner join Simple instance