How to retrieve data from two tables whose column names are the same?
+3
A:
Use aliases, ie.
select table1.field as table1field, table2.field as table2field from table1
join table2 on ...
wimvds
2010-03-10 10:10:14
A:
If you need all the columns (not Union), set alias for each column for one of the tables.
Kangkan
2010-03-10 10:10:25
A:
If you want to include rows from both tables, you can use UNION ALL
:
SELECT Col1, Col2, Col3 FROM Table1
UNION ALL
SELECT Col1, Col2, Col3 FROM Table2
Mehrdad Afshari
2010-03-10 10:10:50
Downvoters: When I started to write the answer there were no comment explaining what exactly the OP wants. As you can see, I started my answer with "If...". It's funny that I get downvotes because the OP decided to accept my answer :)
Mehrdad Afshari
2010-03-10 16:06:56
+1 to get you out of the hole. I understand. Additionally a rightfully accepted answer shouldn't have a negative number associated.
John K
2010-03-14 21:47:41
A:
You can use alias
select a.col_name, b.col_name from table1 a, from table2 b
where a.userid =b.userid // condition as per your comments in question
Ravi Gupta
2010-03-10 10:10:56
A:
Use alias names ?? :-)
SELECT t1.col1 as name1 , t2.col1 as name2 from table1 t1, table2 t2
Richie
2010-03-10 10:11:18