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

Posted December 18, 2008 at 9:19 AM by Ben Nadel

Tags: SQL

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.



Reader Comments

Dec 23, 2008 at 9:35 AM // reply »
7 Comments

I've done this quite a few times. Its why I've trained myself to always use the alias, even when working with a single table.


Dec 23, 2008 at 9:40 AM // reply »
11,243 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).


Mar 12, 2010 at 6:17 AM // reply »
1 Comments

Yes that did help. Thanks


Mar 15, 2010 at 10:01 AM // reply »
11,243 Comments

@Dugeen,

Awesome. Glad this could help.


Jan 12, 2011 at 12:33 PM // reply »
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.


Feb 16, 2011 at 6:22 PM // reply »
1 Comments

Thank you so much for this!


Feb 18, 2011 at 9:59 AM // reply »
11,243 Comments

@Shahzad, @Dempsay,

Glad this helped :)


Sep 27, 2012 at 2:50 AM // reply »
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


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 22, 2013 at 5:35 PM
Script Tags, jQuery, And Html(), Text() And Contents()
This is still an issue 2 years later. jQuery is supposed to remediate these cross browser issues, no? I have been unable to find any statement from the jQuery team calling this behavior "by de ... read »
May 22, 2013 at 12:44 PM
Ask Ben: Query Loop Inside CFScript Tags
In cf10, if you call a function that has: local.result = {}; local.result.msg = ""; local.svc = new query(); local.svc.setSQL("SELECT * FROM..."); local.obj = local.svc.exe ... read »
May 22, 2013 at 12:29 PM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben: What version of Java are you using? Also, did you test users.id to see what Java reports as the data type? I wonder if it's not a Java primitive data type, but getting returned as something ... read »
May 22, 2013 at 11:47 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Dana, Awesome - so it looks like this bug was fixed in ColdFusion 10. Thanks so much for double-checking that. ... read »
May 22, 2013 at 11:37 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
When I c&p and run on cf10, I get: Selected User IDs: 1,4 User 1 selected: YES - YES User 2 selected: NO - NO User 3 selected: NO - NO User 4 selected: YES - YES User 5 selected: NO - ... read »
May 22, 2013 at 11:27 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Tom, Good thought, but no dice. Both of these still exhibit the same behavior: users.id[ users.currentRow ] users[ "id" ][ users.currentRow ] It's just something whacky happening with ... read »
May 22, 2013 at 11:07 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
Could your problem be that "users.id" is actually an ARRAY, not a single value? Perhaps try it again with "users.id[1]" (I only have CF8 here at work). ... read »
May 22, 2013 at 7:52 AM
Nested Views, Routing, And Deep Linking With AngularJS
Hi, Just a quick thank you. As it happens, for my own purposes, the pending ui-router work being done in native angular is likely the one I'll adopt, but your exploration, code and documentation of ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools