Union query

  • Thread starter Thread starter Luis
  • Start date Start date
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?
 
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.
 
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>
 
Back
Top