![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| On my site I often do SELECT counter from counters where id = 10 UPDATE counter set counter = counter + 1 Can I somehow merge them into one statement? Like (in C) SELECT counter++ from counters where id = 10 can that be done? i | |||
| | #2 | ||
| Ignoramus23298 <ignoramus23298@NOSPAM.23298.invalid> wrote: > > SELECT counter from counters where id = 10 > UPDATE counter set counter = counter + 1 > > Can I somehow merge them into one statement? You can do READ-MODIFY-WRITE in a single statement (and thus: free from race condition) like this: UPDATE counters SET counter = (@x:= counter) + 1 WHERE id = 10 However you still need a second statement to read the (old) value of the counter: SELECT @x In case you wonder what @x is - consult the manual <http://dev.mysql.com/doc/refman/5.0/en/user-variables.html> HTH, XL -- Axel Schwenke, Senior Software Developer, MySQL AB Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/ MySQL User Forums: http://forums.mysql.com/ | |||
| Featured Websites | ||||
|
![]() |
| Tags: selectandupdate, statement |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 2 Queries in 1 statement? | Good Man | Database | 2 | 07-01-2007 6:58 PM |
| Why does 'SELECT * FROM countries' truncate characters and SELECT country FROM countries does not ? | PRS | Database | 1 | 07-01-2007 6:31 PM |
| If Statement not working | Jeffrey Ellis | PHP | 3 | 07-01-2007 5:04 PM |
| Include statement | RA | HTML | 4 | 07-01-2007 1:45 PM |
| Why does 'SELECT * FROM countries' truncate characters and SELECT country FROM countries does not ? | PRS | Database | 0 | 05-31-2007 8:48 PM |
| Featured Websites | ||||
|