MySQL left Join,right Join,inner join Simple instance

Source: Internet
Author: User

--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.