SQL Join Brief Introduction

Source: Internet
Author: User

Frontier

Join is one of the important operations of a relational database system, including common joins in SQL Server: INNER JOIN, outer join, and Cross join.

If we want to get data in two or more tables that match rows from one table to rows in another table, then we should consider using join, because the join specifically joins the table or function to query the attributes

CREATE TABLE structure
CREATE TABLE ta_a (id int,name nvarchar), CREATE TABLE ta_b (id int,name nvarchar); insert into Ta_a VALUES (1, ' Pirate INSERT into ta_a values (2, ' Monkey ') insert to Ta_a values (3, ' Ninja ') insert into ta_a values (4, ' Spaghe ') insert INTO T A_b values (1, ' Nuta ') insert into ta_b values (2, ' Pirate ') inserts into Ta_b values (3, ' Darth ') inserts into Ta_b values (4, ' Ni Nja ')
INNER JOIN (Inner join)
SELECT * from Ta_ainner join Ta_bon Ta_a.name=ta_b.name

All outer joins (full Outer join)
SELECT * from Ta_a full OUTER JOIN ta_bon ta_a.name=ta_b.name

Left OUTER join (Outer join)
SELECT * from Ta_aleft OUTER JOIN Ta_bon ta_a.name=ta_b.name

And look at how to take out a record without a table B, or a left outer join.

SELECT * from Ta_aleft OUTER JOIN ta_bon ta_a.name = Ta_b.namewhere ta_b.id is null

Look at another situation, but also with the full outer join, take out the intersection of a and B data

SELECT * from Ta_afull OUTER JOIN ta_bon ta_a.name=ta_b.namewhere ta_a.id are Nullor ta_b.id is NULL

End

The above is about the SQL join some simple knowledge of the collation, I hope you have a little help!

SQL Join Brief Introduction

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.