SQL Subqueries Subqueries in SELECT 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

Subqueries can also be used in the SELECT part of the outer query. The following query shows all weather table columns with the corresponding states from the cities table.

SELECT w.*,  (SELECT c.state FROM cities AS c WHERE c.name = w.city ) AS state 
FROM weather AS w;


Got any SQL Question?