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

https://leetcode.com/problems/combine-two-tables/

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
select p.FirstName,p.LastName,a.City,a.State from Person as p left join Address as a on p.PersonId = a.PersonId;

  

时间: 2024-12-28 22:39:38

LeetCode 175 Combine Two Tables mysql,left join 难度:0的相关文章

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 +--

LeetCode-Algorithms #001 Two Sum, Database #175 Combine Two Tables

最近两周一直感觉学习比较松懈, 打算加大一点强度, 从今天开始, 希望能在每天正常进度完成后在LeetCode上选一两题写一写, 同时学习一下高手的做法. LeetCode - Algorithms #001 Two Sum 给定一个整数数组, 找出其中两个元素, 使其和等于目标值, 返回这两个元素在原数组中的索引组成的数组. 可以假设有且只有一组正解, 且每个元素只能使用一次. 我的思路: 其实想不到什么好的方法, 遍历就好, 非常素朴的回答: 1 class Solution { 2 pub

LeetCode:Combine Two Tables - 跨表查询

1.题目名称 Combine Two Tables(跨表查询) 2.题目地址 https://leetcode.com/problems/combine-two-tables/ 3.题目内容 现在有两张表Person和Address,它们的表结构如下: 表Person: +-------------+---------+ | Column Name | Type    | +-------------+---------+ | PersonId    | int     | | FirstNam

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

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

【leetcode】Combine Two Tables

突然发现leetcode出sql题了,找了道最简单的,找找自信.. 题目如下: Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId is the primary key c

175. Combine Two Tables (Easy)

Source: https://leetcode.com/problems/combine-two-tables/#/description Description: Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +----------

【SQL】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 +--

LeetCode SQL: Combine Two Tables

SELECT FirstName, LastName, City, State FROM Person p LEFT JOIN Address a ON p.PersonId = a.PersonId 居然出SQL的题目了,左连接就行

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

因为对数据库的内容早都忘得差不多了,所以我的第一感觉是: select Person.FirstName, Person.LastName, Address.City from Person, Address where Person.PersonId=Address.PersonId 结果出错了: 因为至少这个人是存在的,只是没有她的地址,你不至于搜不到吧, 但是我这种写法是引用两个表,从两个表中获取数据,就是找两者相同的情况下的结果. 使用join 可以连接两个表: join: 如果表中有一