[LeetCode] 175.Combine Two TablesTable: Person
Table: Address
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 LeetCode also has a question about database. Let's do it. This is the first question. It is relatively simple. It is a question of joint search between two tables. We need to use Join operation. For some Join operations, you can read my previous blog SQL Left Join, Right Join, Inner Join, and Natural Join. The most direct way is to use Left Join to join the two tables according to PersonId: Solution 1: SELECT Person.FirstName, Person.LastName, Address.City, Address.State FROM Person LEFT JOIN Address ON Person.PersonId = Address.PersonId; When using Left Join, we can also use the Using keyword to declare which column name we want to use for the join: Solution 2: SELECT Person.FirstName, Person.LastName, Address.City, Address.State FROM Person LEFT JOIN Address USING(PersonId); Or we can add the Natural keyword so that we don't have to declare specific columns and MySQL can search for the same columns by itself: Solution 3: SELECT Person.FirstName, Person.LastName, Address.City, Address.State FROM Person NATURAL LEFT JOIN Address; References: https://leetcode.com/discuss/21216/its-a-simple-question-of-left-join-my-solution-attached https://leetcode.com/discuss/53001/comparative-solution-between-left-using-natural-left-join This is the end of this article about SQL implementation of LeetCode (175. Join two tables). For more relevant SQL implementation of joining two tables, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Specific use of Node.js package manager npm
>>: HTML background color gradient achieved through CSS
The effect to be achieved is: fixed zoom in twice...
This article shares with you how to use canvas an...
In Windows operating system, the program to query...
System environment: centos7.4 1. Check whether th...
Table of contents introduction Indexing principle...
As the title says, otherwise when the page is revi...
Starting from MySQL 5.7, many security updates ha...
Unlike other types of design, web design has been ...
Flex layout is also called elastic layout. Any co...
Hexo binds a custom domain name to GitHub under W...
This article example shares the specific code of ...
You can use the attribute in HTML5 <input="...
Table of contents 1. Page Rendering 2. Switch tag...
Today I was asked what the zoom attribute in CSS ...
Preface In general development, images are upload...