DEV Community

Cover image for COMBINE TWO TABLES
michael-2509
michael-2509

Posted on

COMBINE TWO TABLES

Chalenge
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.

Check leetcode for more info.

Approach
In this challenge we are to write a SQL code to read data from two separate tables. let's review some basis of SQL and the SQL statements I would use.

SQL is a language used to interact with the database. SQL stands for Structured Query Language.

select clause tells the query what column to read from the data.

from clause tells the query what data to use

joinclause tells query on additional table from which you would love to pull data

on clause specifies a logical statement to combine the table in from and join statement.

Now that we understand this basis, to solve this challenge, I wrote my query using select clause to the pull the firstname, lastname, city and state column. I used the from clause to specify the table I want to pull data, then used the joinclause to specify the other table I needed to pull data from and finally, on clause which I used to combine both tables in join.

Top comments (0)