SubQueries

  • Allows you to construct a complex query

  • A sub-query is nested inside another query

  • can be nested inside SELECT, INSERT, UPDATE, DELETE

SubQueries with SELECT clause

SELECT movie_name,
       movie_length
FROM movies mv
WHERE movie_length >= (
    SELECT avg(movie_length)
    FROM movies
)

SELECT movie_name,
       movie_length
FROM movies mv
WHERE movie_length >= (
    SELECT avg(movie_length)
    FROM movies
    WHERE movie_lang = 'English'
);

SubQueries With WHERE Clause

SubQueries with JOINS

SubQueries with Alias

Last updated

Was this helpful?