Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This query returns the two most populated cities
- -- for each country using the APPLY operator
- SELECT C.Name, P.Name, P.Population
- FROM Example.Countries C
- CROSS APPLY (
- SELECT TOP (2) I.Name, I.Population
- FROM Example.Cities AS I
- WHERE I.CountryID = C.CountryID
- ORDER BY I.Population
- ) AS P
Add Comment
Please, Sign In to add comment