简体   繁体   中英

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"

Here is the sql statement

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

users: user_id(pk), Username, Password, Address, 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.

you need to use the syntax 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"
;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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