noted
noted

Reputation: 67

Joining two relations with default values

I have two views:

view1   view2
obj    obj attribute
+-+     +-+--+
|A|     |C|27|
+-+     +-+--+
|B|
+-+
|C|
+-+

How can I combine the values and return the output,

obj attribute
 +-+--+
 |A| 0|
 +-+--+
 |B| 0|
 +-+--+
 |C|27|
 +-+--+

with 0's as default values in SQL? I don't want to use PL/SQL.

Upvotes: 0

Views: 86

Answers (1)

erikxiv
erikxiv

Reputation: 4075

SELECT v1.obj, NVL(v2.attribute, 0)
FROM view1 v1
LEFT JOIN view2 v2 on v1.obj = v2.obj

Upvotes: 2

Related Questions