Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL Subquery.

Similar presentations


Presentation on theme: "SQL Subquery."— Presentation transcript:

1 SQL Subquery

2 What is Subquery? A Subquery or Inner query or a Nested query is a query within another SQL query (main query) Usually located in WHERE or HAVING clause A subquery is used to return data or set of data that will be used in the main query as a condition to further restrict the data to be retrieved Subqueries can be used with the following SQL statements along with the comparison operators like !=, <>, =, <, >, >=, <=, IN, NOT IN

3 MULTIPLE-ROW SUBQUERY
What is Subquery? SCALAR SUBQUERY MULTIPLE-ROW SUBQUERY

4 MULTIPLE-COLUMN SUBQUERY
What is Subquery? MULTIPLE-COLUMN SUBQUERY

5 Where do we start? FINAL RESULT R3 R2 R1 4
MAIN QUERY Subquery will be execute first, result from subquery will be passed to the main query for further process When reading or writing SQL subqueries, you should start from the bottom upwards, working out which data is to be passed to the next query up. R2 R1 SUBQUERIES

6 Questions Display employee number, first name, last name and salary for any employees whose salary is greater than average salary? Display department number and department name that do not involve in any projects. Display employee number, first name, last name, sex, education level, and department number who has similar sex and education level with employee number

7 ROLLBACK VS COMMIT list command options [ENTER]
TYPE THESE CODE list command options [ENTER] update command options using c off [ENTER] select empno, firstnme from employee where empno = [ENTER] update employee set firstnme = 'MALIK' where empno = [ENTER] commit rollback [ENTER]


Download ppt "SQL Subquery."

Similar presentations


Ads by Google