PHP& MYSQL:如何在子查询中解析不明确的列名

时间:2014-08-27 13:59:08

标签: php mysql

尝试查询以下嵌套查询

SELECT ur.userID, us.fullname
FROM tbl_user_recipe AS ur JOIN tbl_user_settings AS us ON ur.userID = us.userID
WHERE relationship = 'analyzed' AND userID IN 
( SELECT ux.userID
  FROM tbl_user_recipe AS ux
  WHERE ux.relationship = 'collected'
);

我得到以下内容,并想出原因?

#1052 - Column 'userID' in IN/ALL/ANY subquery is ambiguous 

1 个答案:

答案 0 :(得分:2)

您需要在此处为​​别名添加前缀:

WHERE relationship = 'analyzed' AND ur.userID IN