http://sqlfiddle.com/#!4/7cf20/5/0
CREATE TABLE Contacts
(con_id int, Name varchar2(5), Data varchar2(11))
;
INSERT ALL
INTO Contacts (con_id, Name, Data)
VALUES (1, 'email', 'a@gmail.com')
INTO Contacts (con_id, Name, Data)
VALUES (2, 'phone', '123')
INTO Contacts (con_id, Name, Data)
VALUES (3, 'email', 'b@gmail.com')
INTO Contacts (con_id, Name, Data)
VALUES (4, 'phone', '456')
SELECT * FROM dual
;
CREATE TABLE Link
(acct_id int, con_id int)
;
INSERT ALL
INTO Link (acct_id, con_id)
VALUES (1, 1)
INTO Link (acct_id, con_id)
VALUES (1, 2)
INTO Link (acct_id, con_id)
VALUES (2, 3)
INTO Link (acct_id, con_id)
VALUES (2, 4)
SELECT * FROM dual
;
Запрос -
select * from (
select acct_id, name, Data
from contacts c, Link l
where c.con_id = l.con_id
)
pivot (max(Data) for name in ('email' as Email,'phone' as Phone));
Вывод -
ACCT_ID EMAIL PHONE
1 a@gmail.com 123
2 b@gmail.com 456