我试图用两个键连接两个表。加入代码如下:
select
col1, col2, col3, col4
from
data a
join
data1 b on a.col1 = b.col1 and a.col3 = b.col3
我遇到错误:
Query Error: Error: ER_NON_UNIQ_ERROR: Column 'col1' in field list is ambiguous
CREATE TABLE data
(
Id Serial,
col1 VARCHAR(70) NOT NULL,
col3 varchar(70),
col2 integer,
PRIMARY KEY(Id)
);
CREATE TABLE data1
(
Id Serial,
col1 VARCHAR(70) NOT NULL,
col3 varchar(70),
col4 integer,
PRIMARY KEY(Id)
);
SQL fiddle带有样本数据
最佳答案
这是不明确的,因为 postgres 想知道你想要从哪个表中获取 col1
。
为 select 子句中的字段添加别名。例如。选择 a.col1...
关于sql - SQL错误中的复合键连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51005434/