Presentation is loading. Please wait.

Presentation is loading. Please wait.

IFS180 Intro. to Data Management Chapter 11 - Subqueries.

Similar presentations


Presentation on theme: "IFS180 Intro. to Data Management Chapter 11 - Subqueries."— Presentation transcript:

1 IFS180 Intro. to Data Management Chapter 11 - Subqueries

2 Chapter 11 – Subqueries Nothing more than embedded select statements within a SQL clause Three sub query types defined within the standard: Row Sub Query – returns multiple columns but only one row. ** Not Supported ** Table Sub Query – Used for complex results and used in FROM statements Scalar Sub Query – returns one column and one row ** Does not have to be in From Clause **

3 Chapter 11 Subqueries Scalar Sub Query Can be located in any SQL clause (list of expressions, where, having, group) One column / one row ONLY implies….? Implies a where clause must be used in sub query to insure one/column / one row is returned Very effective when combined with aggregate functions (MIN, MAX, Std Dev, First, Last, Sum, AVG, Var)

4 Chapter 11 Sub Queries Sub Query processing occurs with the inner most sub query first and ‘backwards’ through the sub query hierarchy Single row sub query (returns one row) uses comparison operator of: OperatorMeaning =Equal to > Greater than >=Greater or equal to <Less than <=Less or equal to <>Not equal to

5 Chapters 11 Sub Query Examples Produce a report of Bowler names and the Team Name the Bowler is on (select expression as a column reference) Produce a report of Bowlers names with a average score less than ‘Black’ or ‘Alastair Black’ Produce a report of bowlers names and averages which are less than the league average

6 Chapter 11 Sub Queries Multiple Row sub queries (Set Membership) Return more than one row from the sub query Use multiple row comparison operators OperatorMeaning INEqual to any member in the set Any / SomeCompare to each value returned AllCompare to every value returned

7 Chapter 11 Examples Find the bowlers that have the same average as the lowest average on each team Produce a report of bowlers that might have an unfair ‘home lane’ advantage for the tournaments Produce a report of bowlers that have average scores less than anyone with a last name of ‘Kennedy’


Download ppt "IFS180 Intro. to Data Management Chapter 11 - Subqueries."

Similar presentations


Ads by Google