如何从列名相同的两个表中检索数据

时间:2022-04-10 20:20:13

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

如何从列名相同的两个表中检索数据?

5 个解决方案

#1


1  

If you want to include rows from both tables, you can use UNION ALL:

如果要包含两个表中的行,可以使用UNION ALL:

SELECT Col1, Col2, Col3 FROM Table1
UNION ALL
SELECT Col1, Col2, Col3 FROM Table2

#2


3  

Use aliases, ie.

使用别名,即。

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

#3


0  

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

如果需要所有列(而不是Union),请为其中一个表的每个列设置别名。

#4


0  

Use alias names ?? :-)

使用别名? :-)

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

#5


0  

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

#1


1  

If you want to include rows from both tables, you can use UNION ALL:

如果要包含两个表中的行,可以使用UNION ALL:

SELECT Col1, Col2, Col3 FROM Table1
UNION ALL
SELECT Col1, Col2, Col3 FROM Table2

#2


3  

Use aliases, ie.

使用别名,即。

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

#3


0  

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

如果需要所有列(而不是Union),请为其中一个表的每个列设置别名。

#4


0  

Use alias names ?? :-)

使用别名? :-)

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

#5


0  

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