References in a sub-select
Have you ever had a sub-select where you really needed to reference a value in the outer query? I know I have! The naive way would be to run the outer query and then loop over the results running the inner query on each one. Luckily, there's a better way. The Correlated subquery. Check it out! The example given is
See how the sub-select references the outer query? It's SQL magic.