Data Collection from Two tables

L

Lisa

I have two tables that have some of the same data types and i want to bring
them into a query together with a new column that indicates what table they
came from example:

Table 1
ID (auto num)
Date
User
Function
Purpose
20 other fields (I don't need)

Table 2
ID (auto num)
Date
User
Function
Purpose
20 other fields (I don't need)

Query Results
ID
Date
User
Function
Purpose
Table Name

Can this be done through a SQL Query?

Thanks.
 
R

Ryan

You could just name the columns in the query whatever you want. Like this...

Table 1 IDs:[Tabel 1].[ID]
Table 1 Date:[Tabel 1].[Date]
Table 2 User:[Tabel 2].[User]

Notice I declared the table [Tabel 1].[Id] . The reason I did this is
because if you just dragged the ID column from Table 1 and Tabel 2 into the
query, it would ask you which table to use since there are more than one
table with that same column.

I hope this helps.
 
B

Bob Barrows [MVP]

Lisa said:
I have two tables that have some of the same data types and i want to
bring them into a query together with a new column that indicates
what table they came from example:

Table 1
ID (auto num)
Date
User
Function
Purpose
20 other fields (I don't need)

Table 2
ID (auto num)
Date
User
Function
Purpose
20 other fields (I don't need)

Query Results
ID
Date
User
Function
Purpose
Table Name

Can this be done through a SQL Query?
A union query sounds like what you need:

select "Table1" As Source,<fields you want> from Table1
union all

select "Table2",<fields you want> from Table2
order by source,ID
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top