Collections:
VALUES() - Column Value for "ON DUPLICATE KEY UPDATE"
How to obtain the inserting value of given column in the "ON DUPLICATE KEY UPDATE" clause using the VALUES() function?
✍: FYIcenter.com
VALUES(col) is a MySQL built-in function that returns the inserting value of a given column and use it in the "ON DUPLICATE KEY UPDATE" clause. For example:
CREATE TABLE MyTable (id INTEGER UNIQUE, count INTEGER); INSERT INTO MyTable VALUES (1, 1) ON DUPLICATE KEY UPDATE count = count+VALUES(count); INSERT INTO MyTable VALUES (1, 1) ON DUPLICATE KEY UPDATE count = count+VALUES(count); INSERT INTO MyTable VALUES (1, 1) ON DUPLICATE KEY UPDATE count = count+VALUES(count); INSERT INTO MyTable VALUES (1, 1) ON DUPLICATE KEY UPDATE count = count+VALUES(count); SELECT * FROM MyTable; -- +------+-------+ -- | id | count | -- +------+-------+ -- | 1 | 4 | -- +------+-------+
Reference information of the VALUES() function:
VALUES(col): val Returns the inserting value of the given column. Arguments, return value and availability: col: Required. The column name referred in the INSERT statement. val: Return value. The inserting value of the given column. Available since MySQL 4.0.
⇐ UPDATEXML() - Updating Child Element in XML
2023-12-17, 208🔥, 0💬
Popular Posts:
How To Count Rows with the COUNT(*) Function in SQL Server? If you want to count the number of rows,...
What Happens If the UPDATE Subquery Returns Multiple Rows in MySQL? If a subquery is used in a UPDAT...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...
Where to find answers to frequently asked questions on Storage Engines: MyISAM, InnoDB and BDB in My...
Is SQL Server Transact-SQL case sensitive? No. Transact-SQL is not case sensitive. Like the standard...