Subqueries

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_ids first.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *