Lesson 25
Select By Id | SQL Basic Select | HackerRank Solution
Summary
SQL Lesson Summary: Selecting by ID
In this lesson, we explored the exercise of selecting a city by its ID from the SQL section on HackerRank.
Overview
- Table:
city
- Columns: ID, name, country code, district, population
- Task: Query all columns for the city with ID
1661
.
Steps Taken
-
Visualize Data:
- Run the query
SELECT * FROM city;
to view the dataset and identify the structure of the data.
- Run the query
-
Filtering Data:
- To filter the data, use the SQL query:
SELECT * FROM city WHERE ID = 1661;
- Since
ID
is a numeric type, quotes are not required.
- To filter the data, use the SQL query:
-
Execution:
- Run the code to retrieve the row corresponding to the city with ID
1661
, displaying all relevant information.
- Run the code to retrieve the row corresponding to the city with ID
Conclusion
The final output successfully shows the city information for ID 1661
. The exercise demonstrates how to use the SELECT
statement to filter data based on a specific ID.
Video Transcript
Hey everybody, welcome to another lesson. I will do the exercise select by ID from the
basic select subsection of the SQL section from HackerRank. Let's get started. We have
the stable city with the columns ID name, country code, district, and population. And
we're asked to query all columns that is going to use star for the select statement. For
a city with the ID 1661 that we have to filter by the ID column with the value 1661. Okay,
if you want to visualize the data you can always do select star from city to see what
it looks like and click run code. And as you can see this is what the data looks like each
row has information about the city and as you can see the first column is the ID and
that's what we want to filter by. There is one of them that has the ID 1661 that's the
row we want to filter. So we're going to go here we want all columns so star and after
from city we say where and we have to say ID is equal to 1661 and ID is a number so
I don't need quotes here. Let's run the code. And there you go this is the row with the
city of ID 1661 and that's the information for the other columns. I'm going to click
submit and there you go that's select by ID.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: