https://leetcode.com/problemset/database/

ACM退役,刚好要学sql,一定要刷题才行,leetcode吧。

这一题,说了两个表,一个左一个右吧,左边的personId是唯一的,但是右边的PersonId是不唯一的,所以不去重。

然后,总结下各种join的用法。

1、inner join,On XXX,需要左边有,右边也有,就输出该行。

2、outer join / 有些书叫 full join,左边有,右边没,也输出,右边没的就用NULL代替。同理右边有,左边没,也输出。也是NULL

3、left join,如果左边有,右边没,就输出NULL,但是右边有,左边没,不输出。这题用了这个。

4、right 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 join用法的更多相关文章

  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 (组合两个表)

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

  4. Leetcode 175. Combine Two Tables

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

  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. PartyLocation的Post请求问题---debug

    这里,遇到了一个debug: @Override public void setPrimaryPartyLocation(PartyLocation partyLocation) { if (!get ...

  2. java Iterator类

    查看java源码. /* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE ...

  3. Nor Flash工作原理

    http://blog.chinaunix.net/uid-26876150-id-3723678.html Nor Flash 具有像内存一样的接口,它可以像内存一样读,却不可以像内存一样写,Nor ...

  4. linux core文件机制

    在程序不寻常退出时,内核会在当前工作目录下生成一个core文件(是一个内存映像,同时加上调试信息).使用gdb来查看core文件,可以指示出导致程序出错的代码所在文件和行数. 1.core文件的生成开 ...

  5. python 根据字典中的key,value进行排序

    #coding=utf-8 import requests,json,collections,base64,datetime def sort(datas): data=json.dumps(data ...

  6. mac上编译 arm linux gnueabi交叉编译工具链toolchain

    crosstool-ng 编译和安装 交叉编译工具下载: git clone git@github.com:secularbird/crosstool-ng.git   切换到mac编译分支 git ...

  7. xml文件绑定chenckbox选择框

    //xml文件如下: <?xml version="1.0" encoding="utf-8" ?> <CallReson> <! ...

  8. Web Api 测试工具

    1.调用POST方法:使用Chrome流量器的PostMan工具. 前端模拟发送数据/调试的好工具:Chrome下的Postman-REST Client 下载地址 https://chrome.go ...

  9. java项目中获取文件路径的几种方法

    // 第一种: 2 File f = new File(this.getClass().getResource("/").getPath()); // 结果: /Users/adm ...

  10. zookeeper客户端使用第三方(zkclient)封装的Api操作节点

    1.引入依赖 <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</a ...