MySQL INSERT ON DUPLICATE KEY UPDATE upsert
SQL Dasun Kalupahana 88 views
INSERT INTO page_views (page, views)
VALUES ('/home', 1)
ON DUPLICATE KEY UPDATE views = views + 1;
Inserts a row, or updates it if a unique key already exists. The table needs a UNIQUE or PRIMARY KEY on the column you match.
Learn more on the blog
MySQL
PostgreSQL vs MySQL Performance: Real Benchmarks Compared
Last updated: 7 November 2026. See the update log at the end."Which...
8 min read
MySQL
MySQL Too Many Connections (Error 1040): Causes and Fixes
Your site suddenly shows a database error, and the log says this:ERROR...
5 min read
MySQL
Upgrade MySQL 8.0 to 8.4: What Breaks and How to Check
MySQL 8.0 reached end of life in April 2026, which means no...
7 min read