I have a master detail relationship between a person and its friends:
person
id name
-- ------
1 Jones
2 Smith
3 Norris
friends
id personId friendName
-- -------- ----------
1 1 Alice
2 1 Bob
3 1 Charly
4 1 Deirdre
5 2 Elenor
A person can have as many friends as he wants. I want to create a view that selects all persons together with the first three friends it finds; something like this:
id name friend1 friend2 friend3
-- ---- ------- ------- -------
1 Jones Alice Bob Charly
2 Smith Elenor <null> <null>
3 Norris <null> <null> <null>
How do I do this with standard SQL? (Microsoft SQL Server 2005).