Beginning SQL
Beginning SQL Beginning SQL
Summary Queries within Queries This chapter covered the nesting of a query inside another query, a powerful tool that you can use when faced with tricky data extraction questions. Specifically, this chapter covered the following topics: ❑ A subquery is just like a normal query, with SELECT clauses, WHERE statements, and GROUP BY and HAVING clauses. ❑ Subqueries can be included in a SELECT statement’s column listing, or they can be used inside a WHERE statement to enable results to be filtered. ❑ Aggregate functions are commonly used with subqueries because a subquery must normally return just one record for each record in the main query. ❑ A subquery can return multiple rows when used with an IN, ANY, ALL, or EXISTS operator. These operators function as follows: ❑ The IN operator is used to find out whether a value is in one of the values returned by a subquery. ❑ The ANY operator allows a comparison between a value and any of the values returned by a subquery. Comparisons are not limited to just equals (=); rather, you can use any comparison operator, such as greater than (>), less than (
- Page 510: 8 Queries within Queries This chapt
- Page 514: There are no films with a value in
- Page 518: The error wording depends on the da
- Page 522: Now execute the query. You receive
- Page 526: The query provides the following re
- Page 530: If you execute this query, you can
- Page 534: To obtain the same results as you w
- Page 538: MemberId 1 10 14 6 5 8 7 11 15 4 13
- Page 542: Now NOT EXISTS returns true, and as
- Page 546: This is the same as the query just
- Page 550: clause specifying that the film’s
- Page 554: 4. Next, quickly double-check a few
- Page 558: Now that you’ve confirmed that th
- Page 566: 9 Advanced Queries In database prog
- Page 570: FOREIGN KEY (OrderId) REFERENCES Or
- Page 574: INSERT INTO Orders(OrderId, MemberI
- Page 578: INSERT INTO OrderItems(OrderId,Film
- Page 582: A more complex question could be,
- Page 586: Advanced Queries What you really wa
- Page 590: FirstName and LastName. You need to
- Page 594: 2. The film club chairperson also w
- Page 598: Executing the preceding query provi
- Page 602: GROUP BY SalesPerson.SalesPersonId,
- Page 606: Executing the preceding SQL creates
- Page 610: ❑ Use IN with your subqueries. Wh
Summary<br />
Queries within Queries<br />
This chapter covered the nesting of a query inside another query, a powerful tool that you can use when<br />
faced with tricky data extraction questions. Specifically, this chapter covered the following topics:<br />
❑ A subquery is just like a normal query, with SELECT clauses, WHERE statements, and GROUP BY<br />
and HAVING clauses.<br />
❑ Subqueries can be included in a SELECT statement’s column listing, or they can be used inside a<br />
WHERE statement to enable results to be filtered.<br />
❑ Aggregate functions are commonly used with subqueries because a subquery must normally<br />
return just one record for each record in the main query.<br />
❑ A subquery can return multiple rows when used with an IN, ANY, ALL, or EXISTS operator.<br />
These operators function as follows:<br />
❑ The IN operator is used to find out whether a value is in one of the values returned by a<br />
subquery.<br />
❑ The ANY operator allows a comparison between a value and any of the values returned<br />
by a subquery. Comparisons are not limited to just equals (=); rather, you can use any<br />
comparison operator, such as greater than (>), less than (