31271 Lecture 9: Database Fundamentals Notes

85 views2 pages
5 Jun 2018
School
Course
Professor
Lecture 9: SQL III
Simple Subquery
A subquery is a query within a query.
It is used in WHERE and HAVING conditions.
The subquery will execute once.
Most commonly used to find the maximum or minimum
An equivalent way to finding max or min is to use the ALL operator
o Select productdescription, productstandardprice from product_t where
productstandardprice>= ALL (Select productstandardprice from product_t);
The IN operator will test if something is included in the list that is returned from a subquery.
The ANY operator will test if the value is included in the list.
Rules for All and Any
When a subquery returns more than one value:
o Any and All will be used to link the subquery and main query
When All is used:
o Every value returned by the subquery must satisfy the comparison operation
When Any is used:
o One or more values returned y the subquery must satisfy the comparison operation.
Join vs. Subquery
Some queries could be accomplished by either a join or a subquery however it is up to you
which you wish to use.
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents