Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Use Existing Values in UPDATE Statements
How To Use Existing Values in UPDATE Statements? - MySQL FAQs - Understanding SQL INSERT, UPDATE and DELETE Statements
✍: FYIcenter.com
If a row matches the WHERE clause in a UPDATE statement, existing values in this row can be used in expressions to provide new values in the SET clause. Existing values are represented by column names in the expressions. The tutorial exercise below shows a good example:
mysql> UPDATE fyi_links SET id = id+200, counts = id*2 WHERE id >= 500; Query OK, 5 rows affected (0.01 sec) Rows matched: 5 Changed: 5 Warnings: 0 mysql> SELECT id, url, notes, counts, DATE(created) FROM fyi_links WHERE id >= 500; +-----+-------------------+-------+--------+---------------+ | id | url | notes | counts | DATE(created) | +-----+-------------------+-------+--------+---------------+ | 801 | moc.retneciyf.ved | Wrong | 1602 | 2006-04-30 | | 802 | moc.retneciyf.abd | Wrong | 1604 | 2006-08-31 | | 803 | moc.retneciyf.aqs | Wrong | 1606 | 2006-08-31 | | 810 | | Wrong | 1620 | 2006-08-31 | | 700 | moc.retneciyf.www | Wrong | 1400 | 2006-08-31 | +-----+-------------------+-------+--------+---------------+ 5 rows in set (0.00 sec)
This statement increased values in the id column by 200. It also updated the counts column with the newly increased id value.
2007-05-11, 4902👍, 0💬
Popular Posts:
An application needs to load a library before it starts to run, how to code? One option is to use a ...
How To Concatenate Two Character Strings? - MySQL FAQs - Introduction to SQL Basics If you want conc...
What will be printed as the result of the operation below: #define swap(a,b) a=a+b;b=a-b;a=a-b; void...
Which bit wise operator is suitable for checking whether a particular bit is on or off? The bitwise ...
How To Wirte a Simple JUnit Test Class? This is a common test in a job interview. You should be able...