MySQL Subquery
MySQL Subquery
A subquery in MySQL is a query, which is nested into another SQL query and
embedded with SELECT, INSERT, UPDATE or DELETE statement along with the various
operators. We can also nest the subquery with another subquery.
A subquery is known as the inner query, and the query that contains subquery is
known as the outer query.
The inner query executed first gives the result to the outer query, and then the
main/outer query will be performed.
SELECT category_name FROM categories WHERE category_id =( SELECT MIN(category_id) from movies);
It gives a result
o The subqueries make the queries in a structured form that allows us to isolate
each part of a statement.
o The subqueries provide alternative ways to query the data from the table;
otherwise, we need to use complex joins and unions.
o The subqueries are more readable than complex join or union statements.