Reputation: 159
Need your assistance on building a SQL query on the below requirement:
I have two tables as below:
TABLE A:
TASKNAME HOSTNAME
---------------------------
12 A1
34 B
22 C1
43 D
65 E1
93 F
TABLE B:
HOST NODE
----------------------
X ABC
X ABC
Y BV
B YTW
B IJK
D WWQ
D UWY
N J1
F ING
F UPI
I need to run the SQL query to compare these two TABLES and from table A it has to look for HOSTNAME value with HOST field in table B and the final outcome should be like below :
TASKNAME HOSTNAME
---------------------------
12 A1
34 YTW
34 IJK
22 C1
43 WWQ
43 UWY
65 E1
93 ING
93 UPI
Values B, D and F are common between those two tables.
Upvotes: 0
Views: 49
Reputation: 70668
You need a JOIN
and NVL
:
SELECT A.TASKNAME,
NVL(B.NODE,A.HOSTNAME) AS HOSTNAME
FROM TableA A
LEFT JOIN TableB B
ON A.HOSTNAME = B.HOST;
Upvotes: 3