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

MySQL #39;user_id#39; in where clause is ambiguous problem(MySQL user_id in where 子句是不明确的问题)

本文介绍了MySQL 'user_id' in where 子句是不明确的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何纠正我从下面的代码中不断得到的问题,其中声明了 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.

这篇关于MySQL 'user_id' in where 子句是不明确的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:MySQL 'user_id' in where 子句是不明确的问题

基础教程推荐