DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 970,177 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›