Results 1 to 2 of 2
  1. #1
    Joined
    Oct 2001
    Location
    AZ
    Age
    39
    Posts
    575

    union query and retrieving table names

    I've got a union query setup to look at three different tables (will eventually be more), which it is pulling info just fine. However, I have no idea which table each result is coming from. Is there a way to return that table value on each hit, saying where it got the result from?

  2. #2
    Joined
    Oct 2001
    Location
    Southern Ontario
    Age
    45
    Posts
    13,194

    Re: union query and retrieving table names

    You can always create a new field and set the values in this field to reflect which table the data came from. Example: If you have table1, table2 and table3 you can union all the data and create a new column called source to identify the source of the data. Here's how you'd do that:

    Code:
    SELECT *, 't1' AS source FROM table1
    UNION SELECT *, 't2' AS source FROM table2
    UNION SELECT *, 't3' AS source FROM table3;
    You can then continue this pattern for as many tables as you'd like to union.

    edit: This is assuming you're using M$ Access.
    Last edited by Spankin Partier; 09-17-2005 at 12:21 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •