MySQL 'user_id' in where 子句是不明确的问题

2021-11-20 00:00:00 mysql mysql-error-1052

如何纠正我从下面的代码中不断得到的问题,其中声明了 where 子句中的 'user_id' 不明确.提前感谢您的帮助.

How can I correct the problem I keep getting from the code below which states 'user_id' in where clause is ambiguous. Thanks for the help in advance.

这是mysql表.

SELECT user.*, user_info.* 
FROM user 
INNER JOIN user_info ON user.user_id = user_info.user_id
WHERE user_id='$user_id'

推荐答案

您只需要指定使用哪个 user_id,因为 user_infouser 表有一个名为 user_id 的字段:

You simply need to specify which user_id to use, since both the user_info and user table have a field called user_id:

... WHERE user.user_id='$user_id'

SQL 不会容忍这种歧义,因为据它所知,这两个字段可以代表完全不同的数据.

SQL wouldn't tolerate this ambiguity, since for what it knows, both fields can represent totally different data.

相关文章