Not in one query, but you can make two queries for multiple rows.
The MySQL equivalent (as you already know :)
INSERT INTO Table1 (...) VALUES(...) ON DUPLICATE KEY UPDATE column=column+1 ;
or
INSERT INTO Table1 (...) ( SELECT ... FROM ... ) ON DUPLICATE KEY UPDATE column=column+1 ;
The second form can be written with two queries as:
UPDATE Table1 SET (...) WHERE Column1 = 'SomeValue' ; INSERT INTO Table1 (...) ( SELECT ... FROM ... WHERE 'SomeValue' NOT IN ( SELECT Column1 FROM Table1 ) ) ;
You can also reorder and insert new rows first and then update all rows if this suits your data better.
* Note that the IN and NOT IN subqueries may possibly be converted to the equivalent JOIN and LEFT JOIN with check for NOT NULL forms LEFT JOIN with check for NOT NULL .
ypercubeᵀᴹ
source share