Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL view 2 tables

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2010-12-06 : 09:47:14
I have two tables that are almost identical. An Open Order Table and a History Table.

Is there a way to create a SQL view that will list all records in both tables?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-12-06 : 09:51:28
CREATE VIEW All_Orders AS
SELECT col1, col2, col3 FROM OpenOrders
UNION ALL
SELECT col1, col2, col3 FROM OrderHistory

Change the column list in both SELECT statements to meet your needs.
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-12-06 : 09:54:16
quote:
Originally posted by Vack

I have two tables that are almost identical. An Open Order Table and a History Table.

Is there a way to create a SQL view that will list all records in both tables?




CREATE VIEW YourView
AS

SELECT <ColumnList>, 'O' FROM OpenOrderTable
UNION ALL
SELECT <ColumnList>, 'H' FROM OpenOrderTableHistory

'O' Or 'H' to Identify data is from which table. If you dont have column in tables

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page
   

- Advertisement -