Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Subqueries in SQL

Uploaded by

ravinsingh1008
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Subqueries in SQL

Uploaded by

ravinsingh1008
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Welcome to

INTERNSHIP STUDIO
Module 03 | Lesson 06
Analyzing Data with SQL

Subqueries in SQL

WWW.INTERNSHIPSTUDIO.COM
Introduction to Subqueries

•Subqueries are powerful tools in SQL that allow you to nest one query inside
another query.

•A subquery is a query that is embedded within the main query and is used to
retrieve data based on certain conditions.

WWW.INTERNSHIPSTUDIO.COM
Benefits of Subqueries
•Subqueries provide a flexible way to retrieve specific data by incorporating
conditional logic.

•They enable complex filtering, aggregation, and comparison of data from


multiple tables.

•Subqueries can be used in various parts of a SQL statement, such as the


SELECT, FROM, WHERE, and HAVING clauses.

WWW.INTERNSHIPSTUDIO.COM
Types of Subqueries
•Scalar Subqueries: Retrieve a single value as the result of the subquery.

•Single-Row Subqueries: Retrieve a single row as the result of the subquery.

•Multi-Row Subqueries: Retrieve multiple rows as the result of the subquery.

•Correlated Subqueries: Reference columns from the outer query within the
subquery.

WWW.INTERNSHIPSTUDIO.COM
Using Subqueries
•Subqueries can be used in different parts of a SQL statement to perform various
tasks.

•They can be used to filter rows, perform calculations, create derived tables, and
more.

WWW.INTERNSHIPSTUDIO.COM
Subquery Examples
•Example 1: Retrieve all students with a GPA higher than the average GPA.

•Example 2: Retrieve the major(s) with the highest number of students.

•Example 3: Retrieve all students who have taken courses in a specific department.

WWW.INTERNSHIPSTUDIO.COM
Syntax of Subqueries
•Subqueries can be written using parentheses and placed within the main query.

•The result of the subquery is used in the main query to retrieve the desired data.

WWW.INTERNSHIPSTUDIO.COM
SUMMARY
You got Next
this
•Subqueries provide a flexible and powerful
way to retrieve data based on specific
session
Demonstration on Workbench
conditions in SQL.

•They enable complex filtering, aggregation,


and comparison of data from multiple tables.

•Understanding how to use subqueries allows


for more advanced and targeted data retrieval
in SQL.

WWW.INTERNSHIPSTUDIO.COM

You might also like