当前位置:网站首页>Getting started with SQL - combined tables
Getting started with SQL - combined tables
2022-07-26 09:55:00 【Xiao Tang Xuejie】
surface : Person
+-------------+---------+
| Name | type |
+-------------+---------+
| PersonId | int |
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
personId Is the primary key column of the table .
This table contains some people's ID And their last and first names .
surface : Address
+-------------+---------+
| Name | type |
+-------------+---------+
| AddressId | int |
| PersonId | int |
| City | varchar |
| State | varchar |
+-------------+---------+
addressId Is the primary key column of the table .
Each row of the table contains a ID = PersonId Information about people's cities and states .
Write a SQL Query to report Person The last name of each person in the list 、 name 、 Cities and states . If personId Your address is not in Address In the table , The report is empty null .
With In any order Return result table .
The query result format is as follows .
Example 1:
Input :
Person surface :
+----------+----------+-----------+
| personId | lastName | firstName |
+----------+----------+-----------+
| 1 | Wang | Allen |
| 2 | Alice | Bob |
+----------+----------+-----------+
Address surface :
+-----------+----------+---------------+------------+
| addressId | personId | city | state |
+-----------+----------+---------------+------------+
| 1 | 2 | New York City | New York |
| 2 | 3 | Leetcode | California |
+-----------+----------+---------------+------------+
Output :
+-----------+----------+---------------+----------+
| firstName | lastName | city | state |
+-----------+----------+---------------+----------+
| Allen | Wang | Null | Null |
| Bob | Alice | New York City | New York |
+-----------+----------+---------------+----------+
explain :
There is no personId = 1 The address of , So their cities and States return null.
addressId = 1 Contains personId = 2 Address information for .
source : Power button (LeetCode)
link :https://leetcode.cn/problems/combine-two-tables
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
The connection of data table is :
1、 Internal connection ( Natural join ): Only rows that match two tables can appear in the result set
2、 External connection : Include
(1) The left outer join ( The table on the left is unrestricted )
(2) Right connection ( The table on the right is unrestricted )
(3) Full outer join ( There are no restrictions on the left and right tables )
3、 Self join ( The connection occurs in a base table )
All in all :
The left link shows all on the left and the same on the right and left .
The right connection shows all on the right and the same on the left and right .
The inner connection is to show only the parts that meet the conditions .
# Write your MySQL query statement below
select A.FirstName,A.LastName,B.City,B.State
FROM Person A left join Address B
on A.PersonId=B.PersonId边栏推荐
- 一种分布式深度学习编程新范式:Global Tensor
- (2) Hand eye calibration of face scanner and manipulator (eye out of hand: nine point calibration)
- Mo team learning notes (I)
- M-ary number STR to n-ary number
- JS judge the data types object.prototype.tostring.call and typeof
- EOJ 2020 January race E-number transformation
- Wechat applet development
- Wechat applet learning notes 2
- The combination of officially issued SSL certificate and self signed certificate realizes website two-way authentication
- js 表格自动循环滚动,鼠标移入暂停
猜你喜欢

Wechat applet learning notes 1

Development to testing: a six-year road to automation starting from 0

Mqtt x cli officially released: powerful and easy-to-use mqtt 5.0 command line tool

2022 zhongkepan cloud - server internal information acquisition and analysis flag
![Sqoop [environment setup 01] CentOS Linux release 7.5 installation configuration sqoop-1.4.7 resolve warnings and verify (attach sqoop 1 + sqoop 2 Latest installation package +mysql driver package res](/img/8e/265af6b20f79b21c3eadcd70cfbdf7.png)
Sqoop [environment setup 01] CentOS Linux release 7.5 installation configuration sqoop-1.4.7 resolve warnings and verify (attach sqoop 1 + sqoop 2 Latest installation package +mysql driver package res

El table implements adding / deleting rows, and a parameter changes accordingly

Fiddler packet capturing tool for mobile packet capturing

Spolicy request case

SSG framework Gatsby accesses the database and displays it on the page

一种分布式深度学习编程新范式:Global Tensor
随机推荐
面试突击68:为什么 TCP 需要 3 次握手?
Solve NPM -v sudden failure and no response
Double authentication of server and client
JS 连等赋值操作
Server memory failure prediction can actually do this!
Node memory overflow and V8 garbage collection mechanism
RMQ学习笔记
面试突击68:为什么 TCP 需要 3 次握手?
Mysql5.7.25 master-slave replication (one-way)
解决npm -v突然失效 无反应
POJ 1012 Joseph
Xiaobai makes a wave of deep copy and shallow copy
In Net 6.0
Network flow learning notes
Solve proxyerror: CONDA cannot proceed due to an error in your proxy configuration
Flutter event distribution
MySQL的逻辑架构
Tableviewcell highly adaptive
(2) Hand eye calibration of face scanner and manipulator (eye out of hand: nine point calibration)
Wechat H5 payment on WAP, for non wechat browsers