0% found this document useful (0 votes)
5 views10 pages

SQL Subquery Examples and Practices

The document provides examples and explanations of SQL subqueries, detailing how to retrieve specific data based on conditions such as average scores or salaries. It includes instructions for writing queries to display student names, employee details, and book costs relative to other entries. Additionally, it outlines the structure of subqueries with examples and encourages practice by asking the reader to write their own subqueries.

Uploaded by

Sanffred Joju
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)
5 views10 pages

SQL Subquery Examples and Practices

The document provides examples and explanations of SQL subqueries, detailing how to retrieve specific data based on conditions such as average scores or salaries. It includes instructions for writing queries to display student names, employee details, and book costs relative to other entries. Additionally, it outlines the structure of subqueries with examples and encourages practice by asking the reader to write their own subqueries.

Uploaded by

Sanffred Joju
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

SQL – Subquery

SQL – Subquery

How do we write SQL queries to get the required output for the following
statements

Display name of all the students if their score is greater than the avg score of the
class.

Display details of all the employees whose salary is less than the avg salary of the
department

Display details of all the books having cost less than the cost of Book “C
Programming”
SQL - Subquery
SQL – Subquery

Select * from TableName WHERE

FieldName {Operator} Select FieldName from TableName

Outer Query Inner Query


SQL – Subquery

Retrieving records using subquery :

To list the Cust_ID and Loan_No for all Customers who have taken a
loan of amount greater than the loan amount of Customer (Cust_ID = 104).
Subquery execution steps
SQL Subquery- another example

• List customer names of all customers who have taken a loan > $3000.00
SQL Subquery- another example

• List customer names of all customers who have the same Account_type as
Customer ‘Jones Simon’ .
About – SQL Subquery
SQL Subquery- another example

Practice: Write 3 subqueries based on the above Table


1.
2.
3.

You might also like