Hear us Roar
Article:
 |
|
SQL Subqueries
|
| Subject: |
|
mySQL help |
| Date: |
|
2001-11-24 14:26:17 |
| From: |
|
the_newt
|
Response to: mySQL help
|
|
MySQL does not yet support subqueries/sub-selects, but they're working on it. Its just not a priority. There are ways around it though.
Your question seems vague but I'll try to answer as best as I can. I'm assuming you want the last id in the table. MAX() is a summary function and isn't really what you want to use to get the last id in the table. It will work but the results can be pretty sketchy.
UPDATE <table> set item_name='bar' WHERE id IN( SELECT MAX(id) FROM <table>)
could be rewriten as
UPDATE <table> set item_name='bar' WHERE id = LAST_INSERT_ID(table_name.id)
I'm not sure why you would want to do this as record updates should always be updated against a primary key. You're asking for trouble if you don't. Both statements above will always update the last inserted record in the table and have a high possibility of messing up the records.
Hope this helps and John please step in if I'm wrong.
The Newt
|
|
| |