You are on page 1of 1

What is a Subquery?

A query in the where clause is known as subquery or nested query.

Ex 1: Who has the maximum account balance.

Select * from account master


Where currentbalance = ( select max(currentbalance) from account master )

Ex 2: Who has the Second maximum account balance.


Select name from account master
Where (Select max(currentbalance) from account master)
(Where currentbalance < select
max(currentbalance) from account master)

The Better Query is:


Select * from account balance
Where currentbalance = (
Select min(currentbalance)
From account master
Where currentbalance IN (
(Select DISTINCT Top 3 Currentbalance
From account master
Order by Currentbalance DESC
)
)
)

You might also like