tags:

views:

115

answers:

5

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
A: 

If you need all the columns (not Union), set alias for each column for one of the tables.

Kangkan
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
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
+1 to get you out of the hole. I understand. Additionally a rightfully accepted answer shouldn't have a negative number associated.
John K
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
A: 

Use alias names ?? :-)

SELECT t1.col1 as name1 , t2.col1 as name2 from table1 t1, table2 t2  
Richie