0% found this document useful (0 votes)
1 views9 pages

Practical 5 Slides

The document provides an overview of MySQL subqueries, which are nested queries used for intermediate calculations or data retrieval. It explains the use of subqueries in different SQL clauses, including WHERE and FROM, and discusses the application of comparison operators and IN/NOT IN operators. Additionally, it distinguishes between inner queries and outer queries, as well as correlated subqueries that reference the outer query's columns.

Uploaded by

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

Practical 5 Slides

The document provides an overview of MySQL subqueries, which are nested queries used for intermediate calculations or data retrieval. It explains the use of subqueries in different SQL clauses, including WHERE and FROM, and discusses the application of comparison operators and IN/NOT IN operators. Additionally, it distinguishes between inner queries and outer queries, as well as correlated subqueries that reference the outer query's columns.

Uploaded by

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

ILS3A01

Practical 5 Class Slides

2025-04-08
Understanding MySQL Functions
In WHERE In FROM With IN
Clause Clause and NOT IN

Table Correlated
subqueries subqueries
What is a subquery?
• Definition: A subquery is a query nested within another SQL query,
used to perform intermediate calculations or retrieve data that the
main query will utilize.​

• Purpose: Subqueries allow for complex data retrieval operations by


breaking down queries into manageable parts

A MySQL subquery is called an inner query whereas


the query that contains the subquery is called an
outer query. A subquery can be used anywhere that
expression is used and must be closed in
parentheses.
• You can use comparison operators e.g., =, >, < to compare a
single value returned by the subquery with the expression in the
In the WHERE WHERE clause.
Syntax:

Clause SELECT columNames


FROM tableName
WHERE condition =/>/< (Subquery);
When you use a subquery with a FROM clause, the
In the FROM result set returned from a subquery is used as a
temporary table. This table is referred to as a derived
clause table or materialized subquery.
With IN and NOT If a subquery returns more than one value, you can
use other operators such as IN or NOT IN operator in
IN operators the WHERE clause.

Syntax: Syntax:
SELECT columnNames SELECT columnNames
FROM tableName FROM tableName
WHERE condition NOT IN( WHERE condition IN(
SELECT columnName SELECT columnName
FROM tableName); FROM tableName);
With IN and NOT If a subquery returns more than one value, you can
use other operators such as IN or NOT IN operator in
IN operators the WHERE clause.
A subquery that returns multiple rows and columns,
Table Subqueries functioning as a derived table
Correlated A subquery that references columns from the outer
query, executing once for each row processed by the
Subqueries outer query.

You might also like