Add column to query result

mouse88

Registered User.
Local time
Today, 06:01
Joined
Apr 29, 2009
Messages
13
I have the following sql statement:

Code:
SELECT * FROM Autoglass UNION ALL SELECT * FROM AutoscreenNetwork UNION ALL SELECT * FROM Autowindscreens UNION ALL SELECT * FROM Glasscare UNION ALL SELECT * FROM MobileWindscreens UNION ALL SELECT * FROM NationalWindscreens

This just unions all records from all tables, however what im looking to do is have a column added to the result table which will contain the name of the table each record came from.

Is this possible?

Appreciate any help
 
Sure:

SELECT *, "Autoglass" AS SourceTable
FROM Autoglass
UNION ALL
SELECT * , "AutoscreenNetwork" AS SourceTable
FROM AutoscreenNetwork
...
 
I should add that having all those tables is probably a normalization issue. I'd expect one table with a field identifying whatever the tables now represent.
 

Users who are viewing this thread

Back
Top Bottom