sgowd
sgowd

Reputation: 2260

Merging two views in PostgreSQL

I have two views in below format.

ProductId Version IsAvailable
123       1       Yes
124       1       No
125       1       Yes
126       1       No

ProductId Version IsShippable
123       1       Yes
124       1       Yes
125       1       No
127       1       Yes

I need to merge these two tables into a single table:

ProductId Version IsAvailable IsShippable
123       1       Yes         Yes
124       1       No          Yes
125       1       Yes         No
126       1       No          Null
127       1       Null        Yes

How can I write the query to achieve this?

Upvotes: 2

Views: 2319

Answers (1)

Fahmi
Fahmi

Reputation: 37473

Use full outer join between 2 views like below:

select a.ProductId, a.Version, IsAvailable, IsShippable 
from tableA a
full outer join tableB b on a.productid =b.productid and a.version=b.version

Upvotes: 1

Related Questions