I have a table that I want to join some other tables on to. The table called "OfficePers" has a field for the Office Location ID as well as a field for the IDs of people who work in that location and another field with their names. For example, the table is of the following format:
| OfficeLocation | PersonID |
|-------------- | -------- |
|321 | 2323 |
|321 | 2355 |
|321 | 1234 |
|321 | 7899 |
|321 | 32091 |
|321 | 777 |
|1654 | 4232 |
|121243 | 345 |
|121243 | 343 |
|121243 | 111 |
What I want to do is create a subquery that returns one result per office location and creates aliases for each personID and name - so the above table would be transformed into something like the following:
| OfficeLocation | PersonID_1 | PersonID_2 | PersonID_3 | PersonID_4| PersonID_5| PersonID_6|
| -------------- | ----------- |----------- |----------- |-----------|-----------|-----------|
| 321 | 2323 | 2355 | 1234 | 7899 | 32091 | 777 |
| 1654 | 4232 | | | | | |
| 121243 | 345 | 343 | 111 | | | |
I was thinking of perhaps doing something like just joining the "OfficePers" table on itself multiple times but I'm not sure what function I could use to parse out each Person ID - I'm familiar with using Max and Min but that wouldn't work with a case of having more than 2 Person IDs at the same location.