Consider two tables
TABLE PERSON
Code:
ID,name
1 foo1
2 foo2
3 foo3
and
TABLE VALUES
Code:
ID_PERS property value
1 | age | 20
1 | address | street of flowers
2 | age | 29
1 | city| PARIS
3 | address | street
My goal is to get results like:
Code:
1 | foo1 | 20 | street of flowers | PARIS
2 | foo2 | 29 | (null) | (null)
3 | foo3 | (null) | street | (null)
That I arrived with queries like:
PHP Code:
SELECT ID,NAME,
(SELECT value from TABLE_VALUES WHERE ID_PERS=ID AND type='age'),
(SELECT value from TABLE_VALUES WHERE ID_PERS=ID AND type='address'),
(SELECT value from TABLE_VALUES WHERE ID_PERS=ID AND type='city')
FROM PERSON;
It works when I have one 'age', one 'address' per PERSON. When there are multiple addresses, I have multiple rows returned and so the request fails. Is this normal?
Solution: add AND rownum = 1 to each subquery.
Problem: I only have one return value that I did not choose.
Question: How to return all values in repeating the People?
Like:
Code:
1 | foo1 | 20 | street of flowers | (null)
1 | foo1 | 20 | path of poplars | (null)
1 | foo1 | 20 | (null) | PARIS
1 | foo1 | 20 | (null) | MARSEILLE
2 | foo2 | 29 | (null) | (null)
3 | foo3 | (null) | street | (null)
(example: 2 addresses and two cities)
Bookmarks