The trick with this compared to the other questions (e.g. "Oracle convert rows to columns") is that my column values are arbitrary strings, rather than something I can use with decode. Take this query:
The description table here maps people's names to descriptions, but each person can have multiple descriptions e.g. "wears a hat" or "is tall".
Select firstName, lastName,
(Select description from descriptions --This can return any number of rows (0 or more)
where description.firstName = people.firstName
and description.lastName = people.lastName
and rownum <= 3)
from people
where age >= 25;
I would want an output like this:
FIRSTNAME LASTNAME DESCRIPTION1 DESCRIPTION2 DESCRIPTION3
Jeremy Smith Tall Confused (null)
Anne Smith (Null) (Null) (Null)
Mark Davis Short Smart Strong
In the case of less than 3 descriptions, I want nulls there. In the case of more than 3 descriptions, I want to just leave them out.
I am using Oracle 11.1. Can this be done efficiently?