0

以下是我的查询和相关的错误。我究竟做错了什么?

update aaalogin 
  set name = 
      ( select aaacontactinfo.emailid 
        from aaacontactinfo 
        WHERE aaalogin.user_id = aaausercontactinfo.user_id 
          and aaausercontactinfo.contactinfo_id = aaacontactinfo.contactinfo_id
      );

我明白了

错误:“where 子句”中的未知列“aaausercontactinfo.user_id”

4

2 回答 2

0

尝试

UPDATE aaalogin SET name =
(
    SELECT aaacontactinfo.emailid
    FROM aaacontactinfo, aaausercontactinfo
    WHERE aaalogin.user_id = aaausercontactinfo.user_id
    AND aaausercontactinfo.contactinfo_id = aaacontactinfo.contactinfo_id
);

子查询中不需要aalogin。如果使用,它甚至可能在子查询中返回多条记录。

于 2012-06-15T15:57:30.290 回答
0

aaausercontactinfo未包含在FROM表格列表中,请尝试:

UPDATE aaalogin SET name =
(
    SELECT aaacontactinfo.emailid
    FROM aaacontactinfo, aaalogin, aaausercontactinfo
    WHERE aaalogin.user_id = aaausercontactinfo.user_id
    AND aaausercontactinfo.contactinfo_id = aaacontactinfo.contactinfo_id
);
于 2012-06-15T15:39:25.237 回答