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

+-------------+---------+
| 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 WHERE 的时候没有数据匹配就会返回空,但是你比如查询xx的住址可能是有人员信息么有地址这个时候我们用LEFT JON 和RIGHT JOIN

什么意思呢,上语句查询结果你就懂了

#左连接就是左边查询的如果有数据右面如果没有匹配,那么右面的数据可以为空
#SELECT FirstName, LastName, City, State FROM Person left join Address on Person.PersonId=Address.PersonId;
#右连接就是右边查询的如果有数据左面如果没有匹配,那么右面的数据可以为空
SELECT FirstName, LastName, City, State FROM  Address RIGHT  join  Person on  Address.PersonId=Person.PersonId;
时间: 2024-11-08 22:28:07

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

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

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

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

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

Combine Two Tables[leetcode]

# Write your MySQL query statement below #select a.FirstName , a.LastName , b.City , b.State from Person as a , Address as b where a.PersonId = b.AddressId ; select a.FirstName , a.LastName , b.City , b.State from Person as a left join Address as b o

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组合两张表——oracle的左右连接运用

表1: Person +-------------+---------+ | 列名 | 类型 | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId 是上表主键 表2: Address +-------------+---------+ | 列名 | 类型 | +-------------+---

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

[LeetCode] 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 +--