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, 4997👍, 0💬
Popular Posts:
How To Create an Add-to-Google-Reader Button on Your Website? - RSS FAQs - Adding Your Feeds to RSS ...
How is normally a project management plan document organized ? PMP document forms the bible of a pro...
How To Use Subqueries in the FROM clause? - MySQL FAQs - SQL SELECT Statements with JOIN and Subquer...
How can I check for HTML errors? HTML validators check HTML documents against a formal definition of...
What are the core functionalities in XML .NET framework? Can you explain in detail those functionali...