SQL Subqueries Subqueries in WHERE clause

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

The following example finds cities (from the cities example) whose population is below the average temperature (obtained via a sub-qquery):

SELECT name, pop2000 FROM cities 
WHERE pop2000 < (SELECT avg(pop2000)  FROM cities);

Here: the subquery (SELECT avg(pop2000) FROM cities) is used to specify conditions in the WHERE clause. The result is:

namepop2000
San Francisco776733
ST LOUIS348189
Kansas City146866


Got any SQL Question?