Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Include table name in query results

Posted on 2008-10-31
3
Medium Priority
?
455 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 2000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 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