01. One SQL A Day (15/06/22)

Source: Free SQL Questions from LeetCode

175. Combine Two Tables

Table: Person

Table: Address

Write an SQL query to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead.

Return the result table in any order.

The query result format is in the following example.

Example 1:

My SQL Query

SELECT firstName, lastName, city, state
FROM Person
LEFT JOIN Address
ON Person.personID = Address.personID;

  • Showing all personID from Person table even if they don’t have the address in Address table(return null in this case)
  • and getting matching personID records only from Address table(which is personID 2)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store