sql left and right join

join full join: find data that exists in both the left table (main table) and the right table (sub-table)
Left join: The left table (main table) is searched to find the complete set, the existing association of the right table (sub-table) is obtained, and the non-existing table is NULL.
right join right join: just the opposite of left join
Full join association: It is equivalent to combining left join and right join, that is, the left table (main table) is associated with the right table (sub-table). NULL, if the right table has the left table, the left table will display NULL
For example, you now have two tables, student table and grades table, student table has two columns of data: student ID and student name, grades table has three columns of data, grade ID, student ID and total score
Suppose there are three rows of data in the student table, the IDs are 1, 2, and 3, and the names are Zhang San, Li Si, and Zhao Wu.
Suppose there are also three rows of data in the grade table: grade ID is 1, 2, 3, student ID is 2, 3, 5, grade is 60, 85, 90
If you write select * from student table a join grade table b on a. student ID=b. student ID
There will be two data with student IDs 2 and 3
If you write select * from student table a left join grade table b on a. student ID=b. student ID
Three pieces of data with student IDs 1, 2, and 3 will appear, but the grade table information associated with the piece of data with student ID 1 is all NULL
If you write select * from student table a right join grade table b on a. student ID=b. student ID
There will be three pieces of data with student IDs 2, 3, and 5, but the student table information associated with the data with student ID 5 is all NULL
If you write select * from student table a full join grade table b on a. student ID=b. student ID
All data with student IDs 1, 2, 3, and 5 will appear, but the student table information associated with the data with student ID 5 is all NULL, and the data with student ID 1 is associated with all grade table information. is NULL

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326063309&siteId=291194637