Combine Two Tables - Sql - Easy - LeetCode
💻 coding

Combine Two Tables - Sql - Easy - LeetCode

1 min read 128 words
1 min read
ShareWhatsAppPost on X
  • 1The SQL query combines data from the Person and Address tables using a LEFT JOIN.
  • 2It retrieves FirstName, LastName, City, and State for each person.
  • 3The query ensures all persons are included, even if they lack an address.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"The SQL query combines data from the Person and Address tables using a LEFT JOIN."

Combine Two Tables - Sql - Easy - LeetCode

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:

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 your MySQL query statement below
Select p.FirstName, p.LastName, a.City, a.State From Person p Left Join Address a On p.PersonId = a.PersonId;

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

sumitc91

Published on 16 October 2020 · 1 min read · 128 words

Part of AskGif Blog · coding

You might also like

Combine Two Tables - Sql - Easy - LeetCode | AskGif Blog