Leetcode 175. Combine Two Tables】的更多相关文章

一.题目 175. Combine Two Tables 二.分析 连接查询的时候要考虑where和on的区别 where : 查询时,连接的时候是必须严格满足条件的,满足了才会加入到临时表中. on : 查询时,考虑要满足这个条件,如果不满足则不会添加连接的表中的数据. 三.AC代码 SELECT FirstName, LastName, City, State FROM Person p LEFT JOIN Address a ON p.PersonID = a.PersonID;…
https://leetcode.com/problems/combine-two-tables/ Combine Two Tables Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+…
https://leetcode.com/problemset/database/ ACM退役,刚好要学sql,一定要刷题才行,leetcode吧. 这一题,说了两个表,一个左一个右吧,左边的personId是唯一的,但是右边的PersonId是不唯一的,所以不去重. 然后,总结下各种join的用法. 1.inner join,On XXX,需要左边有,右边也有,就输出该行. 2.outer join / 有些书叫 full join,左边有,右边没,也输出,右边没的就用NULL代替.同理右边有…
题目标签: 题目给了我们两个table,让我们合并,根据Person为主. 因为题目说了 提供person 信息,不管这个人有没有地址.所以这里用Left Join. Java Solution: Runtime:  244 ms, faster than 40 % 完成日期:05/22/2019 关键点:Left Join # Write your MySQL query statement below Select FirstName, LastName, City, State From…
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId is the primary key column for this table. Table: Address +--…
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId is the primary key column for this table. Table: Address +--…
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId is the primary key column for this table. Table: Address +--…
因为对数据库的内容早都忘得差不多了,所以我的第一感觉是: select Person.FirstName, Person.LastName, Address.City from Person, Address where Person.PersonId=Address.PersonId 结果出错了: 因为至少这个人是存在的,只是没有她的地址,你不至于搜不到吧, 但是我这种写法是引用两个表,从两个表中获取数据,就是找两者相同的情况下的结果. 使用join 可以连接两个表: join: 如果表中有一…
给定两个表,一个是人,一个是地址,要求查询所有人,可以没有地址. select a.FirstName, a.LastName, b.City, b.State from Person as a left join Address as b Using(PersonId); 详细可参考:https://www.cnblogs.com/grandyang/p/5348900.html…
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId is the primary key column for this table. Table: Address +--…