Reputation: 163
I have following table in db2:
id | person 1 | person 2 | person 3 |
---|---|---|---|
1 | 10 | 12 | 15 |
I now want to make a query that returns the following:
id | person |
---|---|
1 | 10 |
1 | 12 |
1 | 15 |
how can I do this in db2?
Thanks in advance!
Upvotes: 0
Views: 84
Reputation: 12314
It's more efficiently not to scan the same potentially large table multiple times.
Try this:
SELECT T.ID, V.PERSON
FROM MYTAB T, TABLE (VALUES T.PERSON1, T.PERSON2, T.PERSON3) V (PERSON);
Upvotes: 1
Reputation:
Use a UNION:
select id, person1 as person
from the_table
union all
select id, person2
from the_table
union all
select id, person3
from the_table
Upvotes: 1