Page 1 of 1

1 SQL from more than on table without foreign key

Posted: Fri Oct 08, 2004 2:53 am
by anjanesh
I have 3 tables - table1, table2, table3 - all have a field called Name
table1 has 20 Names
table1 has 30 Names
table1 has 50 Names

I want all the names from all the tables in one query (100 names) :
SELECT * FROM table1,table2,table3 will return 30000 names (repeats)
and SELECT DISTINCT(t1.Name),DISTINCT(t2.Name),DISTINCT(t3.Name) FROM table1 t1, table2 t2, table3 t3 doesnt work.

What other options are there ?
Thanks

Posted: Fri Oct 08, 2004 3:27 am
by feyd
you have to attach the tables together somehow in order to use joins correctly or you will get multiples.

maybe you should look into a [mysql_man]union[/mysql_man].. and post your queries in

Code: Select all

tags when [u]not[/u] in php code, please....