0% found this document useful (0 votes)
11 views

SQL Subqueries Presentation

A subquery is a query nested within another SQL query, used in various clauses like SELECT, INSERT, UPDATE, DELETE, or WHERE. There are different types of subqueries, including single-row, multi-row, correlated, and non-correlated subqueries. While subqueries are simple and easy to read, they can be inefficient for large datasets compared to joins.

Uploaded by

bramhdev.patil01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

SQL Subqueries Presentation

A subquery is a query nested within another SQL query, used in various clauses like SELECT, INSERT, UPDATE, DELETE, or WHERE. There are different types of subqueries, including single-row, multi-row, correlated, and non-correlated subqueries. While subqueries are simple and easy to read, they can be inefficient for large datasets compared to joins.

Uploaded by

bramhdev.patil01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

SQL Subqueries

What is a Subquery?

• - A subquery is a query within another query.


• - It can be used in SELECT, INSERT, UPDATE,
DELETE, or WHERE clauses.
Types of Subqueries

• - Single-row Subquery: Returns a single row of


data.
• - Multi-row Subquery: Returns multiple rows
of data.
• - Correlated Subquery: References a value
from the outer query.
• - Non-correlated Subquery: Independent of
the outer query.
Subqueries in SELECT, WHERE, and
FROM Clauses

• - SELECT Clause: SELECT column FROM table


WHERE column IN (SELECT ...);
• - WHERE Clause: SELECT * FROM table WHERE
column = (SELECT ...);
• - FROM Clause: SELECT * FROM (SELECT ...);
Benefits and Drawbacks of Using
Subqueries

• - Benefits: Simple, easy to read, and maintain.


• - Drawbacks: Can be inefficient for large data
sets, slower than joins.
Example of a Subquery in SQL

• Example:
• SELECT * FROM employees WHERE salary >
(SELECT AVG(salary) FROM employees);

You might also like