user290391
user290391

Reputation:

How to retrieve data from two tables whose column names are the same

How to retrieve data from two tables whose column names are the same?

Upvotes: 1

Views: 3565

Answers (5)

Ravi Gupta
Ravi Gupta

Reputation: 4574

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

Upvotes: 0

Richie
Richie

Reputation: 9266

Use alias names ?? :-)

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

Upvotes: 0

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422026

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

Upvotes: 1

Kangkan
Kangkan

Reputation: 15571

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

Upvotes: 0

wimvds
wimvds

Reputation: 12850

Use aliases, ie.

select table1.field as table1field, table2.field as table2field from table1 
join table2 on ...

Upvotes: 3

Related Questions