Example: ---------------------- --------------------------- a table ID name b table ID Job parent_id 1 Sheets 31 1 2 John Doe 2 2 3 Wang Wu 3 Relationship between a.ID and parent_id in 4--------------------------------------------------
Original table above
1. Left connection:
Official explanation: The LEFT join returns records that include all the records in the left table and the equivalent of the join fields in the right table
Left JOIN connect Select a.*,b.* from a left join b on a.id=b.parent_id result is 1 Sheet 3 1 1 2 John Doe 2 2 3 Wang Wu null
2. Right Connection:
Official explanation: Right join returns records that include all records in the right table Uhe and the join fields in the left table are equal
Right connect Select a.*,b.* from a to join b on a.id=b.parent_id The result is 1 sheets 3 1 1 2 John Doe 2 2 null 3 4
3. Internal connection:
Official explanation: Inner join (equivalent connection) returns two tables this is a line that joins fields that are equal
Internal connection Select a.*,b.* from a inner join b on a.id=b.parent_id result is 1 Sheet 3 1 1 2 John Doe 2 2
SQL: Left connection, right connection, inner connection