Definition: A subquery is a query nested within another SQL query. They can be used in SELECT, INSERT, UPDATE, or DELETE statements.Example:
SELECT first_name, last_name
FROM employees
WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = 1000);
Explanation: This retrieves the names of employees who work in departments located in location_id
1000. The inner query fetches the relevant department_id
s first.
Leave a Reply