how to add a column to an existing record?

G

Guest

I've made a union query and I want to add now a column to this query
Beside I want it to get the table name beside each record because these
records belongs to different tables as I said in the begining it's a union
query.

example
table1
table2
table3

union query xyz containing all data in these three tables.

I want to add a column to this query and in this column, i want it to
contain infront of each record the name of the table from which it come from.

please really need your help.
 
G

Guest

Add the following to each select statement in the union query ---
, "YourTableName" AS [TableName]
 
D

Douglas J. Steele

SELECT Field1, FIeld2, "Table1" As DataSource
FROM Table1
UNION
SELECT Field1, FIeld2, "Table2"
FROM Table2
UNION
SELECT Field1, FIeld2, "Table3"
FROM Table3
 
G

Guest

Really thanks alot Karl

KARL DEWEY said:
Add the following to each select statement in the union query ---
, "YourTableName" AS [TableName]
--
KARL DEWEY
Build a little - Test a little


tamerelrefaie said:
I've made a union query and I want to add now a column to this query
Beside I want it to get the table name beside each record because these
records belongs to different tables as I said in the begining it's a union
query.

example
table1
table2
table3

union query xyz containing all data in these three tables.

I want to add a column to this query and in this column, i want it to
contain infront of each record the name of the table from which it come from.

please really need your help.
 
G

Guest

Really thanks alot Douglas

Douglas J. Steele said:
SELECT Field1, FIeld2, "Table1" As DataSource
FROM Table1
UNION
SELECT Field1, FIeld2, "Table2"
FROM Table2
UNION
SELECT Field1, FIeld2, "Table3"
FROM Table3
 

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

Similar Threads


Top