Union query

L

Luis

Hello.
I have a union query that joins 3 tables.
Is it possible that, for each record, the union query
retrieves also the name of the table that the record is
stored?
 
K

Ken Snell

Add a calculated field to each part of the union query that has a text
string (the actual name of the table) as the value of the field:

SELECT *, "NameOfTable" AS TableName FROM .....
UNION SELECT *, "NameOfOtherTable" AS TableName FROM...
etc.

Replace NameOfTable with the actual name of the table.
 
J

John Vinson

Hello.
I have a union query that joins 3 tables.
Is it possible that, for each record, the union query
retrieves also the name of the table that the record is
stored?

You can include the table name as a calculated field in each of the
three SELECT clauses of the UNION:

SELECT "ThisTable" AS Tablename, [FieldX], [FieldA] FROM [ThisTable]
UNION
SELECT "ThatTable", ... FROM [ThatTable]
UNION
<etc>
 

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