SQL join is used to combine rows from two or more tables, including the inner join, the left JOIN, the right join, and the full outer join.
Let's start by describing the data in the table.
First sheet teacher
Second sheet student
The first is inner join,sql as follows
Select * from as Inner Join as on = t.id;
Execution results
Explanation diagram
Left JOIN, can also write left outer join, SQL as follows
Select * from as Left Join as on = t.id;
Execution results
Explanation diagram
Right join, and you can write right outer join,sql as follows
Select * from as Right Join as on = t.id;
Execution results
Explain
Full outer join,mysql does not support full outer join,sql should be written
SELECTs.id ass_id, S.first_name asS_f, S.last_name ass_l, T.first_name asT_f, T.last_name ast_l, T.id ast_id fromStudent ass Left JOINTeacher asT onS.id=t.idUNION SELECTs.id ass_id, S.first_name asS_f, S.last_name ass_l, T.first_name asT_f, T.last_name ast_l, T.id ast_id fromTeacher asT Left JOINStudent asS onS.id=T.id
Output results
Explain
Reference:
Http://www.w3cschool.cc/sql/sql-join.html
Http://stackoverflow.com/questions/38549/difference-between-inner-and-outer-joins
Http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
Http://stackoverflow.com/questions/4796872/full-outer-join-in-mysql
Join Usage for SQL