Primary table
Id name
1 xxxxx
2 yyyyy
3 zzzzzz
Foreign table
Id phonetype phoneno
1 home 111111
1 work 222222
1 mob 333333
2 work 444444
2 mob 555555
I need to display
Name workphone homephone mob
xxxxx 222222 111111 333333
yyyyy 444444 null 555555
How to write the query in sql server 2008
Here are two more methods, just for completeness:
In addition to Marc_s solution, you can also use PIVOTs to achieve this:
Try something like this: