SQL Union Query - include table name as field?

  • Thread starter Thread starter Titian
  • Start date Start date
T

Titian

Greetings

For a union query of two tables, is it possible to include the name of the
table as an additional field for each record, so that I know from which
table a record has come?

What would be the sql code to do that?

thanks
Dan
 
SELECT "tblA" as TableName, Field1, Field2
FROM tblA
UNION
SELECT "tblB", Field1, Field2
FROM tblB
UNION
SELECT "tblN", Field1, Field2
FROM tblN;
 
Back
Top