What is the difference between a scalar subquery and a derived table?
Last updated
A scalar subquery returns exactly one value (one row, one column) and is used wherever a single value fits:
SELECT,WHERE, or expressions.A scalar subquery errors if it returns multiple rows and yields NULL if it returns none.
A derived table is a subquery in the
FROMclause that must have an alias, can return many rows and columns, and is joined or queried like a normal table.
- https://www.sql-practice.online/learn/sql-subqueries
- https://medium.com/@guptaguptalokesh2002/types-of-subqueries-in-sql-13ce378b7baa
- https://learn.microsoft.com/en-us/cosmos-db/query/subquery
- https://dev.to/chat2db/sql-subqueries-power-up-your-data-retrieval-4gma
- https://learn.microsoft.com/en-us/sql/relational-databases/performance/subqueries?view=sql-server-ver17
- https://dev.mysql.com/doc/refman/8.4/en/correlated-subqueries.html
- https://medium.com/@kiamars.mirzaee/sql-subqueries-the-hidden-performance-killers-457a48ca2f01
- https://www.red-gate.com/simple-talk/databases/mysql/subqueries-in-mysql/