derived tables and subqueries can look the same and many people may even think they are the same thing, but there are definitely differences. Don’t worry, even if you don’t know what a derived table or a subquery is in SQL, it should be clear by the time you are done reading below.
A subquery is a SELECT statement that is nested within another statement – that’s why it’s called a subquery, because it’s like having a query within another query . Subqueries are usually used in the WHERE clause as a way to filter out certain rows returned in the result set of the outer query.