简体   繁体   English

MySql错误:字段是歧义(代码1052)

[英]MySql Error: field is ambiguos (code 1052)

I am trying to create a SELECT statement that will be able to extract data from various tables according to certain conditions but i keep getting the same error "Error Code 1052: Column Username in where clause is ambiguouse" 我正在尝试创建一个SELECT语句,该语句将能够根据某些条件从各种表中提取数据,但是我不断收到相同的错误“错误代码1052:where子句中的列用户名不明确”

Here is the sql statement 这是sql语句

SELECT * FROM engineer, users WHERE Username = "James" AND Password = "12345"

Here is what the tables involved look like 这是涉及的表的样子

engineer: user_id(pk), Username, Password, Address, Contact_No 工程师:user_id(pk),用户名,密码,地址,Contact_No

users: user_id(pk), Username, Password, Address, Contact_No 用户:user_id(pk),用户名,密码,地址,Contact_No

I think the error might be in that there is the same Username column in both table but i can't find a proper sql statement that would work. 我认为错误可能是因为在两个表中都有相同的Username列,但我找不到能正常工作的适当的sql语句。

you need to use the syntax table.column_name. 您需要使用语法table.column_name。 So your query can be: 因此,您的查询可以是:

SELECT * FROM engineer, users WHERE engineer.Username = 'James' AND engineer.Password = '12345'

I choose engineer but you can do the same with users or mix the two. 我选择工程师,但您可以对用户执行相同操作,也可以将两者混合使用。 Also note the single quotes around the values. 还要注意值周围的单引号。

SELECT * FROM engineer WHERE Username = "James" AND Password = "12345"
UNION
SELECT * FROM users WHERE Username = "James" AND Password = "12345"
;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM