MySQL update with WHERE clause containing two indexed columns
Supposing you had a MySQL table that stored user details, for simplicity lets call the table 'users' and you had 2 indexes:
1) The auto_increment primary key (users_id)
2) An index on the username (username)
If you were to run an update on a row for example:
UPDATE users SET first_name='tom' WHERE users_id=10 AND username='tomtank';
Naturally you would expect this query to run and perform the update. However, thats not what I discovered. What actually happened was, MySQL ran the query but did not perform the update and reported zero rows affected. However, as soon as I removed the second condition in the WHERE clause, the results were as expected.
Of course one may argue for the necessity of the second condition in the WHERE clause, but I did that simply out of vanity. :)
This is a strange one indeed, and might though I'm not 100% sure be attributed to my version of MySQL (5.1.33). Whatever the case is, I just thought I would share this experience in the hope that it may save someone alot of time and digging.
LAST UPDATED: 8 Dec, 2009 at 01:46 PM
POPULAR TOPICS
TOPICS
- Agriculture
- Architecture
- Art
- Associations
- Automobiles
- Beauty
- Building and Construction
- Business Services
- Education
- Embassies
- Engineering
- Entertainment
- Environment
- Fashion
- Financial and Legal
- Government
- Health
- Hospitality
- Imports and Exports
- Shopping Centres
- Computers and Internet
- Industrial
- NGOs
- Housing and Real Estate
- Religious Bodies
- Security
- Society and Culture
- Sports and Leisure
- Travel and Tourism
- Utilities
- Social Services
- Transportation
by Kejau Touray on 6 Jan, 2010 at 01:50 PM