Leetcode-combine Tables

Source: Internet
Author: User

Description:write a SQL query for a report this provides the following information for each person in the person table, r Egardless If there is a address for each of the those people:

The first time to brush the SQL topic feels good. This topic is probably about connecting the first and second tables together. And the property in the address of the person in the second table may be null. This is obviously a left outer link.

# Write your MySQL query statement belowselect FirstName, LastName, city, state from person left OUTER JOIN Address on (Pe Rson. Personid=address.personid);

Here is the difference between the left and right outer links.

The left outer link is all tuples that list the left relationship, and the right outer link is all tuples that list the right relationship. Let's give an example.
PersonName (Id,name)
Data: (1, Zhang San) (2, John Doe) (3, Harry)
Personposition (id,position)
Data: (1, student) (2, teacher) (4, principal)

Results of the left connection:

Select personname.*,personposition.* from personname left join personposition on Personname.id=personposition.id;
1 31 students
2 Li 42 Teacher
3 Harry NULL NULL

Result of right outer link:

Select personname.*,personposition.* from PersonName right join personposition on personname.id=personposition.id;

1 31 students
2 Li 42 Teacher
Null NULL 4 Principal

Leetcode-combine Tables

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.