Simple tutorial on LEFTJOIN and RIGHTJOIN (ORACLE & amp; MYSQL)

Source: Internet
Author: User
The left and right connections of Oracle are in OraclePL-SQL, and the left and right connections are implemented in the following way: SELECTemp_name, dept_nameFORMEmployee, DepartmentWHEREEmployee. emp_deptid (+) Department. deptid this SQL statement uses the right join, that is, the other side of the location where (+) is connected

The left and right connections of Oracle are in the Oracle PL-SQL, and the left and right connections are implemented in the following way: SELECT emp_name, dept_name FORMEmployee, Department WHERE Employee. emp_deptid (+) = Department. deptid this SQL statement uses the right join, that is, the other side of the location where (+) is connected

Left and right connections of Oracle
In the Oracle PL-SQL, left and right connections are implemented as follows

View the following statements:

SELECT emp_name, dept_name
FORM Employee, Department
WHERE Employee. emp_deptid (+) = Department. deptid

This SQL statement uses the right connection, that is, the other side of the "(+)" is the connection direction. All records on the right side of the equal sign of the right connection are displayed, whether it is matched on the left or not, that is, whether a department does not have an employee in the previous example, the department name will appear in the query results.

Otherwise:

SELECT emp_name, dept_name
FORM Employee, Department
WHERE Employee. emp_deptid = Department. deptid (+)

It is a left join. no matter whether the employee has a Department number that can be matched in the Department table, the employee's record will be displayed.

++ ++ MYSQL

ALeft JoinThe number of records connected to table B is the same as that of Table.
A rightJoinThe number of records connected to table B is the same as that of Table B.
ALeft JoinB is equivalent to B rightJoinA


Table:
Field_K, Field_A
1
3 B
4 c

Table B:
Field_K, Field_ B
1 x
2 y
4 z

Select a. Field_K, a. Field_A, B. Field_K, B. Field_ B
FromLeft JoinB on a. Field_K = B. Field_K

Field_K Field_A Field_K Field_ B
----------------------------------------
1 a 1 x
3 B NULL
4 c 4 z

Select a. Field_K, a. Field_A, B. Field_K, B. Field_ B
From a rightJoinB on a. Field_K = B. Field_K

Field_K Field_A Field_K Field_ B
----------------------------------------
1 a 1 x
NULL 2 y
4 c 4 z

++

This is the case.
Table1 table2
Id, sex1 id sex2
A 1 a 4
B 0
Select id, sex1, sex2 from table1Left JoinTable2 on table1.id = table2.id
Then,
Id sex1 sex2
A 1 4
B 0 null
That is to sayLeft JoinAll records in the left table of the connection will appear. If no relevant records are found in Table 2 based on the connection conditions, the result is null.
RightJoinAll records in the right table are displayed.
InnerJoinOnly records that meet the conditions will appear in the result set.

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.