Solved

Include table name in query results

Posted on 2008-10-31
3
453 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 93

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

630 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