Subquery

A subquery is a SELECT statement nested in another statement.

You can use a subqery in the SELECT, FROM, WHERE and JOIN clauses.

Subquery syntax:

(SELECT colmn_1
FROM table_2)

Examples

SELECT trackid, name, albumid
FROM tracks
WHERE albomid = (
	SELECT albumid
	FROM albums
	WHERE title = 'Let there be rock'
);

SELECT albomid, title
FROM albums
WHERE 10000000 > (
	SELECT sum(bytes)
	FROM tracks
	WHERE tracks.Albomid = albums.Albomid
	)
ORDER BY title;