0% found this document useful (0 votes)
12 views8 pages

SUBQUERIES - Basics

The document provides an overview of SQL subqueries, including examples of basic and correlated subqueries. It also includes sample interview questions related to finding salaries greater than average and displaying employees reporting to a specific manager. The content is proprietary and intended for personal use only, with legal implications for unauthorized distribution.

Uploaded by

murali.dhiviya96
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)
12 views8 pages

SUBQUERIES - Basics

The document provides an overview of SQL subqueries, including examples of basic and correlated subqueries. It also includes sample interview questions related to finding salaries greater than average and displaying employees reporting to a specific manager. The content is proprietary and intended for personal use only, with legal implications for unauthorized distribution.

Uploaded by

murali.dhiviya96
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/ 8

dhiviyamurali.54@gmail.

com
XR0S5B9UT4
Subqueries

Proprietary
This filecontent. © Great
is meant Learning.
for personalAll Rights
use Reserved. Unauthorized use or distribution prohibited.
by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Sub-Queries

• SELECT * FROM table1 WHERE salary > 1000;


• SELECT (SELECT avg(col1) FROM table1), col2, col7 FROM table1

[email protected]
XR0S5B9UT4

Proprietary
This filecontent. © Great
is meant Learning.
for personalAll Rights
use Reserved. Unauthorized use or distribution prohibited.
by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Sub-Queries

• SELECT * FROM table1 WHERE salary > 1000;


• SELECT (SELECT avg(col1) FROM table1), col2, col7 FROM table1
• SELECT * FROM table1 WHERE salary > (SELECT avg(salary) FROM table1)
[email protected]
XR0S5B9UT4

Proprietary
This filecontent. © Great
is meant Learning.
for personalAll Rights
use Reserved. Unauthorized use or distribution prohibited.
by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Sub-Queries

• SELECT * FROM table1 WHERE salary > 1000;


• SELECT (SELECT avg(col1) FROM table1), col2, col7 FROM table1
• SELECT * FROM table1 WHERE salary > (SELECT avg(salary) FROM table1)
• SELECT * FROM (Sub-query) AS T1
[email protected]
XR0S5B9UT4

Proprietary
This filecontent. © Great
is meant Learning.
for personalAll Rights
use Reserved. Unauthorized use or distribution prohibited.
by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Correlated Sub-Queries

• SELECT * FROM employees as e1 WHERE salary >


(SELECT AVG(salary) FROM employees WHERE department_id = e1.department_id)

[email protected]
XR0S5B9UT4

Proprietary
This filecontent. © Great
is meant Learning.
for personalAll Rights
use Reserved. Unauthorized use or distribution prohibited.
by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Sample Interview Questions

• Find the Salary greater than Average salary using Joins or Sub-Queries
• Select salary from table1 where salary > (select avg(salary) from table1)

[email protected]
XR0S5B9UT4

Proprietary
This filecontent. © Great
is meant Learning.
for personalAll Rights
use Reserved. Unauthorized use or distribution prohibited.
by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Sample Interview Questions

• Find the Salary greater than Average salary using Joins or Sub-Queries
• Select salary from table where salary > (select avg(salary) from table1)
• Display employees who are reporting to ADAM
• Select * from employees where manager_id = (select manager_id from
[email protected]
XR0S5B9UT4
employees where name = ADAM)

Proprietary
This filecontent. © Great
is meant Learning.
for personalAll Rights
use Reserved. Unauthorized use or distribution prohibited.
by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.
Sample Interview Questions

• Find the Salary greater than Average salary using Joins or Sub-Queries
• Select salary from table where salary > (select avg(salary) from table1)
• Display employees who are reporting to ADAM
• Select * from employees where manager_id = (select manager_id from
[email protected]
XR0S5B9UT4
employees where name = ADAM)
• Write an SQL query to fetch the Ids that are present in table1 but not
in table2
• SELECT Id FROM table1
WHERE Id Not IN
(SELECT Id FROM table2);

Proprietary
This filecontent. © Great
is meant Learning.
for personalAll Rights
use Reserved. Unauthorized use or distribution prohibited.
by [email protected] only.
Sharing or publishing the contents in part or full is liable for legal action.

You might also like