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.