Subqueries in SQL
Subqueries in SQL
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.
WWW.INTERNSHIPSTUDIO.COM
Types of Subqueries
•Scalar Subqueries: Retrieve a single value 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 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.
WWW.INTERNSHIPSTUDIO.COM