Use INSERT ... ON DUPLICATE KEY UPDATE
. For example:
INSERT INTO `usage`
(`thing_id`, `times_used`, `first_time_used`)
VALUES
(4815162342, 1, NOW())
ON DUPLICATE KEY UPDATE
`times_used` = `times_used` + 1
More Related Contents:
- Insert into a MySQL table or update if exists
- SQLite INSERT – ON DUPLICATE KEY UPDATE (UPSERT)
- Does DB2 have an “insert or update” statement?
- How to SELECT the newest four items per category?
- Simple way to calculate median with MySQL
- Unioning two tables with different number of columns
- NULL in MySQL (Performance & Storage)
- MySQL function to find the number of working days between two dates
- MySQL Trigger to prevent INSERT under certain conditions
- MySQL “NOT IN” query
- Emulate MySQL LIMIT clause in Microsoft SQL Server 2000
- Importance of varchar length in MySQL table
- mySQL :: insert into table, data from another table?
- Return 0 if field is null in MySQL
- MySQL “between” clause not inclusive?
- MySQL syntax for Join Update
- SQL – How to transpose?
- SQL SELECT to get the first N positive integers
- Sorting string column containing numbers in SQL?
- Multiple Ranks in one table
- The difference between ‘AND’ and ‘&&’ in SQL
- How can I make an average of dates in MySQL?
- How to combine aggregate functions in MySQL?
- What is the best way to generate ranks in MYSQL?
- What does collation mean?
- What’s the correct name for an “association table” (a many-to-many relationship) [closed]
- sql pulling a row for next or previous row of a current row
- Row Rank in a MySQL View
- Select Rows with Maximum Column Value group by Another Column
- UPSERT *not* INSERT or REPLACE