Sunday, August 19, 2012

an example of a correlated subquery

SELECT * FROM BigAndSmallNumbers BAS
WHERE BigNumber >
(SELECT AVG(BigNumber)
FROM BigAndSmallNumbers
WHERE SmallNumber = BAS.SmallNumber)

...is an example of a correlated subquery.

 
 

If our BigAndSmallNumbers table looks like this:

SmallNumberBigNumber
218
3234
43456
586746
277
3543
43477
589898
299
3666
49989
598734
599799

 
 

Then our results will be:

SmallNumberBigNumber
277
299
3666
3543
49989
598734
599799

No comments:

Post a Comment