Skip to main content
Ben Nadel at CFCamp 2023 (Freising, Germany) with: Raphael Schürholz
Ben Nadel at CFCamp 2023 (Freising, Germany) with: Raphael Schürholz

MySQL: The Multi-part Identifier "u.id" Could Not Be Bound

By
Published in Comments (10)

I had never seen this error before, so I thought I would just take a second to post it in case anyone tries to Google it. Luckily, my query was extremely small and so the error was obvious from a quick review of the SQL; but, in a large query this might not be readily apparent. Here's the kind of query I was running in MySQL:

UPDATE
	[user]
SET
	is_active = 1
WHERE
	u.id = 4

Can you see what the problem is? My WHERE clause uses an aliased table name, but my UPDATE clause did not alias the table. I am so used to using aliased tables that when I saw the error, it didn't even occur to me that the aliasing itself was causing the issue. Once I removed the alias "u.", the query worked fine.

Again, a really minor note, but I thought it might help someone.

Want to use code from this post? Check out the license.

Reader Comments

15,883 Comments

@Jon,

Agreed; I try to use the alias all the time. I just like it for some reason - I think it adds readability to the query (although that may just be a purely emotional response).

1 Comments

Ah this helped me a lot, mine query was big one and I did aliased the table but after reading this when I checked back the query, there was a typo in alias. :-) So lots of time saved.

1 Comments

I have meet the same question,but I don't think the origin error is the alias but the alias the way use it ,I recommened the way you use it like this:
UPDATE u
SET u.is_active = 1
from users as u
WHERE u.id = 4

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel