Join Usage for SQL

Source: Internet
Author: User

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

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.