How to obtain the table name in a join?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to create a join and a further column showing the table name
from wich the record/row have originated. But I do not know how to obtain the
name, perhaps it is very easy but it is not in my knowledge...

Thans in advance
 
You may need to explain a bit more on what you are trying to do ...

Normally, to display data from (related) Fields from different Tables, you
create a Query which uses the relevant Tables as data source and you link
them as required in the Query, e.g. Inner Join, Left Join, Right Join or no
join at all ...

Since you design the Query, you specify the source Tables so you must know
the Table names in advance.
 
Carlos

Why? As in "why do you want/need to show the table name?"

If your data structure (table design) embeds data in the table name, your
application/database would likely benefit from further normalization.

Can you provide an example?
 
I am sorry I have expressed my ideia in a wrong way, it is not a join
but a union between two tables, I hope this help you to help me...

an example

table1

id name
01 Carlos Adriano Portes
02 john Doe

table2
id name
01 Paul Walker
02 Mary Doe

Union
id name origin_table
01 Carlos Adriano Portes table1
01 Paul Walker table2
02 john Doe table1
02 Mary Doe table2

....

"Van T. Dinh" escreveu:
 
Yes the example is above, read please, and remember that i wrote join instead
of union...I am sorry I made a mistake!

"Jeff Boyce" escreveu:
 
SELECT ID, FirstName, LastName, other fields, "Table1" as TableID
FROM Table1
UNION
SELECT ID, FirstName, LastName, other fields, "Table2" as TableID
FROM Table2
 
Back
Top