A query is used to obtain data in a database. It can be used with various clauses, such as conditional clauses (such as WHERE) and order clauses (such as ORDER BY) to get the query results.
A subquery is a query nested in an upper-layer query. An upper-layer query is generally referred to as a parent query or outer query. The subquery result is returned as input to the parent query or outer query. The parent query takes the subquery result into the calculation to determine the final output.
The SQL language supports multi-level nested queries, which means that one subquery can be nested with other subqueries. Meanwhile, subqueries can be included in various clauses of SQL statements, such as SELECT, FROM, and WHERE.
The following are common query types in SQL statements: