2

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?

4
  • You should show us the original source data and the code for the two views. Commented Aug 31, 2018 at 4:53
  • @TimBiegeleisen sure, but how does that help? Commented Aug 31, 2018 at 4:54
  • Because a view is the product of a query. Unless you used the term "view" to mean "table?" Please clarify whether you are showing us tables or views on top of tables. Commented Aug 31, 2018 at 4:55
  • These are views but both the views and tables work in the same way. Commented Aug 31, 2018 at 4:56

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Doesn't it just join the common rows?
But in this case, the product id is coming null for rows that are not present in tableA.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.