SQL Union Query - include table name as field?


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
 
Ad

Advertisements

D

Duane Hookom

SELECT "tblA" as TableName, Field1, Field2
FROM tblA
UNION
SELECT "tblB", Field1, Field2
FROM tblB
UNION
SELECT "tblN", Field1, Field2
FROM tblN;
 
Ad

Advertisements


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