[英]How to join two sql tables when the common column has different names but information is the same in both tables
[英]How do I join two tables ON a column, that has the same name in both tables?
往上看...
對表名使用別名是最短的。
SELECT a.*, b.*
FROM table1 as 'a'
INNER JOIN table2 as 'b'
ON a.col1 = b.col1
您還可以指定完整的表名稱。
SELECT table1.*, table2.*
FROM table1
INNER JOIN table2
ON table1.col1 = table2.col1
你問的是關系術語中的NATURAL JOIN
。 某些數據庫服務器支持此子句。 我寧願手動指定連接表達式,即使提供程序支持如下子句:
SELECT .... FROM Table1 JOIN Table2 ON Table1.JoinCol = Table2.JoinCol ...
select *
from Table1
inner join
Table2
on Table1.ColumnName = Table2.ColumnName
真的很簡單。
為了完整性(取決於您的DBMS),您可以使用“USING”:
SELECT
...
FROM
table_a
INNER JOIN
table_b
USING
(common_column);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.