hAPPyqirL
hAPPyqirL

Reputation: 101

ORACLE - how to use a CASE WHEN EXISTS statement for rows that do not exist?

I am given the following tables

table 1:

ID  Amount_week_1
05   350

table 2:

ID  Amount_week_2

There are no rows displayed for table 2 as 0 amount was made. However, I would like to combine these info into a new table which looks something like

ID  Amount_week_1  Amount_week_2
05      350             0

May I know how can I go about doing this? I have tried using the EXISTS clause but i might have used it wrongly since it didnt work.

Any help will be greatly appreciated, thank you!

Upvotes: 1

Views: 535

Answers (1)

Sherwin Obciana
Sherwin Obciana

Reputation: 319

You can use LEFT JOIN to combine the two tables.

SELECT table1.id, table1.amount_week_1
     , NVL(table2.amount_week_2, 0) as amount_week_2
FROM   table1
LEFT JOIN table2 on table2.ID = table1.ID

Upvotes: 5

Related Questions