0

In my database I want to add two views and all columns in one of them to the other.

View one:

|Col1 | Col2 |
|     |      |
|     |      |
|     |      |

View two:

|Col1 | Col3 | Col4| Col5 |
|     |      |     |      |
|     |      |     |      |
|     |      |     |      |

My desired result:

|Col1 | Col2 | Col3 | Col4 |
|     |      |      |      |
|     |      |      |      |
|     |      |      |      |

I have attempted this with solutions like:

SELECT Col1, Col2
FROM view1 NATURAL JOIN(
SELECT Col1, Col2, Col3, Col4
FROM view2); 

Ive also tried with other joins but keep getting error that I'm missing key words.

How do I combine the tables the way I wish?

3
  • Can there be col1 in view1 that don't exists in view2? Can there be col1 in view2 that don't exists in view1? Commented Dec 2, 2014 at 10:47
  • All values in Col1 view1 are present in Col1 view2 but there might be values in view2 that are not in view1. Commented Dec 2, 2014 at 11:09
  • Then use Codeek's suggestion and outer-join view1 to view2 (from view1 right join view2or from view2 left join view1). Commented Dec 2, 2014 at 11:22

1 Answer 1

1

I don't know what are your view's schema, but I am assuming col1 from both views match.

SELECT v1.Col1, v1.Col2, v2.Col3,v2.col4
FROM View1 v1
INNER JOIN -- OR FULL OUTER JOIN based on your desired result
View v2
on
v1.col1=v2.col1 -- AND/OR any other matching columns. I couldn't find any other one
Sign up to request clarification or add additional context in comments.

Comments

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.