MySQL INSERT with a Max()+1 Subquery
This was a pain in my ass to figure out so I figured I would post it here in case anyone else needs to insert a record using a Max()+1 Subquery.
I only use the Max()+1 Subquery when the value you want to increase is not the primary key.
View Code MYSQL
INSERT INTO table (row1, row2, row3) SELECT 1 + COALESCE((SELECT MAX(row1) FROM table), 0), 'value2', 'value3' |





Thank you! I wasted an hour trying to do this before finding your site, sorted me out! Cheers
lovely !