简体   繁体   中英

Select 2 column values as one in oracle

First of all, I'm not looking for a CONCAT, but a UNION. But I can't do UNION since there are other columns in the SELECT query.
Below is my table structure and expected result when I search for EmpId=1.
Here is what I have tried so far,
select emp.empId, emp.name, STREET from employee emp, mailing_address mail, office_address off where emp.empId=mail.empId and emp.empId=off.empId
I just don't know what should I put in STREET so I can get the street from both mailing_address and office_address tables in a single shot. Please help.

在此处输入图片说明

SELECT e.EmpId,
       e.Name,
       m.Street
FROM   EMPLOYEE e
       INNER JOIN
       Mailing_Address m
       ON ( e.EmpID = m.EmpID )
WHERE  e.EmpID = 1
UNION
SELECT e.EmpId,
       e.Name,
       o.Street
FROM   EMPLOYEE e
       INNER JOIN
       Office_Address o
       ON ( e.EmpID = o.EmpID )
WHERE  e.EmpID = 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM