I'd really appreciate some pointers on how to handle a query that joins tables that does not return the Cartesian product but puts the below residents into columns on a single returned row. I need to generate some reports and I need to have all related residents from a space on one report per space. I do not have any sample code as I am unsure where to even start.
spaces Table
spaceID|rent
----------------
1 | 1000
2 | 1200
residents Table
id|spaceID|name
--------------------
1 |1 |Joe Smith
2 |1 |Jane Smith
3 |2 |Frank Zakk
4 |2 |Nancy Zakk
5 |2 |Sam Zakk
Expected Result
spaceID |rent |resident1 |resident2 |resident3| resident4
1 |1000 |Joe Smith |Jane Smith| |
2 |1200 |Frank Zakk|Nancy Zakk|Sam Zakk |
My Result using a join
spaceID|rent | name
--------------------------------
1 |1000 |Joe Smith
1 |1000 |Jane Smith
etc...