Leetcode 175. Combine Two Tables

来源:互联网 发布:linux proccess port 编辑:程序博客网 时间:2024/04/29 08:02

175. Combine Two Tables

Total Accepted: 25227 Total Submissions: 73988 Difficulty: Easy

Table: Person

+-------------+---------+| Column Name | Type    |+-------------+---------+| PersonId    | int     || FirstName   | varchar || LastName    | varchar |+-------------+---------+PersonId is the primary key column for this table.

Table: Address

+-------------+---------+| Column Name | Type    |+-------------+---------+| AddressId   | int     || PersonId    | int     || City        | varchar || State       | varchar |+-------------+---------+AddressId is the primary key column for this table.

Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of

 those people:

FirstName, LastName, City, State

本弱渣博主准备开始进军leetcode的数据库内容,主要是题目做的太无聊了,并且没有面试光刷题并没有什么卵用。大牛从名校出来,高GPA,项目牛逼就拿面试了,然后随便刷个题就拿offer了,弱渣项目没有简历关都过不了,刷300题也觉得性价比不高啊


思路:

有俩表,需要把俩表的信息整合,用join。因为是regardless of address所以是left join。也就是左表每一行的信息加右边对应同personId的行信息。


# Write your MySQL query statement belowselect a.FirstName, a.LastName, b.City, b.State from Person a left join Address bon a.personid = b.personid;


0 0
原创粉丝点击