Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
34 views

SQL Subquery

The document discusses SQL subqueries, which are queries nested within other queries. Subqueries return data that is used as a condition in the main query to further restrict results. Subqueries can be used with comparison operators and different types include scalar, multiple-row, and multiple-column subqueries. Subqueries are executed first with results passed to the main query, which is read from bottom to top.

Uploaded by

Alia Safrina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

SQL Subquery

The document discusses SQL subqueries, which are queries nested within other queries. Subqueries return data that is used as a condition in the main query to further restrict results. Subqueries can be used with comparison operators and different types include scalar, multiple-row, and multiple-column subqueries. Subqueries are executed first with results passed to the main query, which is read from bottom to top.

Uploaded by

Alia Safrina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

SQL Subquery

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
What is Subquery?

SCALAR SUBQUERY MULTIPLE-ROW SUBQUERY


What is Subquery?

MULTIPLE-COLUMN SUBQUERY
Where do we start? FINAL RESULT
• Subquery will be execute first, 4 R3 MAIN
QUERY
result from subquery will be
passed to the main query for 3 R2
further process
• When reading or writing SQL R1
subqueries, you should start from 2 SUBQUERIES
the bottom upwards, working out
which data is to be passed to the 1
next query up.
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 000280
ROLLBACK VS COMMIT
TYPE THESE CODE

list command options [ENTER]


update command options using c off [ENTER]
list command options [ENTER]
select empno, firstnme from employee where empno = 000280 [ENTER]
update employee set firstnme = 'MALIK' where empno = 000280
[ENTER]
select empno, firstnme from employee where empno = 000280 [ENTER]
commit
rollback [ENTER]
select empno, firstnme from employee where empno = 000280 [ENTER]

You might also like