Solved

Include table name in query results

Posted on 2008-10-31
3
436 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:Ima Jedi
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 22850395
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
 
LVL 5

Expert Comment

by:JBart_17
ID: 22850415
select 'School1',fieldA, fieldB from table1
select 'School2',fieldA, fieldB from table2
hardcode it in
0
 

Author Closing Comment

by:Ima Jedi
ID: 31512050
Thank you Patrick!  That works perfectly.  It figures that it would be such a simple solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
[MYSQL]: Delete is very slow 4 54
Session that filled up my transaction logs 1 40
MySQL Grouping 2 23
MySQL Error Code 2 0
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now