eg for second largest using sub query

1
Eg for second largest using sub query salary_master: (Sample Data) id name salary 1 AAA 20000 2 BBB 18000 3 CCC 19000 SELECT MAX(salary) from salary_master SELECT * from salary_master where salary < (SELECT MAX(salary) from salary_master) Output: id name salary 2 BBB 18000 3 CCC 19000 Now will process the MAX(salary) instead of * we will get the output Second Largest Value SELECT MAX(salary) from salary_master where salary < (SELECT MAX(salary) from salary_master) Output: 20000

Upload: amal-jose

Post on 28-Sep-2015

216 views

Category:

Documents


3 download

DESCRIPTION

read it

TRANSCRIPT

Eg for second largest using sub querysalary_master: (Sample Data)

id name salary1 AAA 200002 BBB 180003 CCC 19000

SELECT MAX(salary) from salary_master

SELECT * from salary_master where salary < (SELECT MAX(salary) from salary_master)

Output:id name salary2 BBB 180003 CCC 19000Now will process the MAX(salary) instead of *we will get the output Second Largest Value

SELECT MAX(salary) from salary_master where salary < (SELECT MAX(salary) from salary_master)

Output:20000