Lesson 23
Revising the Select Query II | SQL Basic Select | HackerRank Solution
Summary
SQL Lesson Summary
Topic: Revising Select Query
In this lesson, the focus is on revising the SELECT query from the SQL section of HackerRank, specifically Query Number Two.
Objective
- Query the name column from the city table.
- Filter results for:
- Cities located in the USA.
- Cities with a population greater than 120,000.
SQL Query Breakdown
-
SELECT Statement:
- To select only the name column:
SELECT name
- To select only the name column:
-
FROM Clause:
- Indicating the city table:
FROM city
- Indicating the city table:
-
WHERE Clause:
- Filtering conditions:
- Country code should be USA:
WHERE country_code = 'USA'
- Population must be greater than 120,000:
AND population > 120000
- Country code should be USA:
- Filtering conditions:
Final SQL Query
SELECT name
FROM city
WHERE country_code = 'USA' AND population > 120000;
Conclusion
After executing the query, it retrieves a list of city names in the USA with a population exceeding 120,000. This exercise emphasizes filtering data based on multiple criteria in SQL.
This concludes the summary of revising the SELECT query from HackerRank.
Video Transcript
Hey everybody, welcome to another lesson. I will do revising the select query
number two from basic select of the SQL section of HackerRank. So we're asked to
query the name field, that means just the name column instead of all the columns
of the table city, and we want to filter only by American cities, that is the
country code has to be equal to USA. But also the population has to be greater
than 120,000, so we have these two things to filter on. Okay, so let's get
started. I'm going to say select. Now I could be start if it's all columns, I
only want the name column, so name from the name of the table city. Now we need
some filters so I'll add where. Now the first one it has to be from the USA, so
country code is equal to USA. Now and because we have to filter by population
as well, we have to say and population has to be greater than 120,000. Okay,
I'm going to click submit code. And as you can see here, these are the list of
city names from USA with the population greater than 120,000 according to this
data. And that's revising the select query two from HackerRank.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: