Leetcode 175. Combine Two Tables
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的更多相关文章
- LeetCode 175. Combine Two Tables 【MySQL中连接查询on和where的区别】
一.题目 175. Combine Two Tables 二.分析 连接查询的时候要考虑where和on的区别 where : 查询时,连接的时候是必须严格满足条件的,满足了才会加入到临时表中. on ...
- LeetCode 175 Combine Two Tables mysql,left join 难度:0
https://leetcode.com/problems/combine-two-tables/ Combine Two Tables Table: Person +-------------+-- ...
- leetcode 175 Combine Two Tables join用法
https://leetcode.com/problemset/database/ ACM退役,刚好要学sql,一定要刷题才行,leetcode吧. 这一题,说了两个表,一个左一个右吧,左边的pers ...
- LeetCode 175. Combine Two Tables (组合两个表)
题目标签: 题目给了我们两个table,让我们合并,根据Person为主. 因为题目说了 提供person 信息,不管这个人有没有地址.所以这里用Left Join. Java Solution: R ...
- 175. Combine Two Tables【LeetCode】-LEFT JON 和RIGHT JOIN,两张表关联查询-java -sql入门
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...
- [Leetcode|SQL] Combine Two Tables
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...
- sql 中多表查询-leetcode : Combine Two Tables
因为对数据库的内容早都忘得差不多了,所以我的第一感觉是: select Person.FirstName, Person.LastName, Address.City from Person, Add ...
- leetcdoe 175. Combine Two Tables
给定两个表,一个是人,一个是地址,要求查询所有人,可以没有地址. select a.FirstName, a.LastName, b.City, b.State from Person as a le ...
- 【SQL】175. Combine Two Tables
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...
随机推荐
- Android Security
Android Security¶ 确认签名¶ Debug签名: $ jarsigner -verify -certs -verbose bin/TemplateGem.apk sm 2525 Sun ...
- VC分发包版本问题
来源:http://www.cnblogs.com/mixiyou/archive/2010/02/09/1663620.html 之前曾经写过一篇个人经历,是关于VC2005分发包版本不一致而引起应 ...
- 玩Mega8 智能充电器-12. 终于实现-dV检测(转)
源:http://blog.chinaunix.net/uid-10701701-id-91873.html 2010.1.3 5:30终于补齐了. 电池充电的-dv 的检测系列图片请移步: http ...
- HDU 1883 Phone Cell(计算几何)
方法:选取一个点A,以点A为圆心做一个半径为r的圆,然后枚举另一个点B,以B为圆心做一个圆,如果这两个圆有交集,那我们在这个交集内选取一个点做半径为r的圆,这个圆就包括了A和B点,找到交集最多的区域并 ...
- js 编码问题
//字符转换为UTF-8编码 function encutf8(s1) { var stringArray = new Array(); for(var j=0; j<s1.length;j++ ...
- javascript的 replace() 方法的使用讲解
String.prototype.replace() The replace() method returns a new string with some or all matches of a p ...
- VS+VA 开发NDK
工欲善其事,必先利其器. Android NDK开发环境,可选择VIM+插件.Eclipse+CDT等,这里介绍另一种选择:VS+VA 软件准备:Visual studio 2008 // 其他版本也 ...
- AWK----awk与shell交互
1互相调用命令 ls | awk '{if(system("ls " $0)==0) print "file "$0" exsits"}' ...
- redis 学习
http://blog.csdn.net/z69183787/article/category/2923783
- MySQL show status命令参数
Aborted_clients 由于客户没有正确关闭连接已经死掉,已经放弃的连接数量. Aborted_connects 尝试已经失败的MySQL服务器的连接的次数. Binl ...