|
Say I have a table with three fields: PKID UserID PhoneNumber There are three rows Row1: 1 15 123 Row2: 1 15 456 Row3: 1 15 789 You can see that I have three separate phone numbers for userID 15. I want to display that in query results in one row: UserID, PhoneNumber1, PhoneNumber2, PhoneNumber3. I have a much more complex query that gives me correct results in a cartesian product. I'm trying to eliminate the cartesian product.
(comments are locked)
|
|
Here are alternatives for single column csv as well as pivot to separate columns:
(comments are locked)
|
|
or this
(comments are locked)
|
|
See also other questions here with the keyword "pivot"
(comments are locked)
|


Do you want the phoneNumbers in seperate columns or a single column as a comma separated value?
Seperate columns would be preferred. -BJL
Ok, then see the PIVOT solution below:
How many telephone numbers could there be, maximum, for a single person? That might pose a challenge if the number of columns it creates is high
one instance of 4 and many hundreds of 3,2, and 1. So, although there is no physical limit, practically, 5 is all I expect.