Include table name in query results

I have several tables that are all filled with basically the same information but each for a different school.  I need to pull a few pieces of information from each so that I can do some comparison analysis.  The problem is that I need to know which table each result was pulled from so that I know which school it pertains to.  Is there any way to include the actual table name in the results of the query?
Ima JediAsked:
Who is Participating?
 
Patrick MatthewsConnect With a Mentor Commented:
Like this?

SELECT 'table1' AS Source, Col1, Col2, Col3
FROM table1
UNION ALL
SELECT 'table2' AS Source, Col1, Col2, Col3
FROM table2
UNION ALL
SELECT 'table3' AS Source, Col1, Col2, Col3
FROM table3
0
 
JBart_17Commented:
select 'School1',fieldA, fieldB from table1
select 'School2',fieldA, fieldB from table2
hardcode it in
0
 
Ima JediAuthor Commented:
Thank you Patrick!  That works perfectly.  It figures that it would be such a simple solution.
0
All Courses

From novice to tech pro — start learning today.