MDanz Posted April 14, 2010 Share Posted April 14, 2010 i have a column called origin which is type integer(not ascending or descending). All rows have an origin assigned to them can't be duplicated... like two rows with the same origin(integer). when inserting a new row. Just say row 1 has origin 15 and i'm inserting a new row with the same origin(15) how do i go to the next available integer to prevent a duplicate origin? Quote Link to comment https://forums.phpfreaks.com/topic/198578-query-insert-help/ Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Why not set the column to be a primary key and auto increment? If you did that, you won't have to worry about it. Quote Link to comment https://forums.phpfreaks.com/topic/198578-query-insert-help/#findComment-1042140 Share on other sites More sharing options...
andrewgauger Posted April 15, 2010 Share Posted April 15, 2010 INSERT INTO table_name SET origin=(SELECT MAX(origin) FROM table_name)+1 Quote Link to comment https://forums.phpfreaks.com/topic/198578-query-insert-help/#findComment-1042535 Share on other sites More sharing options...
fenway Posted April 17, 2010 Share Posted April 17, 2010 INSERT INTO table_name SET origin=(SELECT MAX(origin) FROM table_name)+1 That's a bad idea -- not thread-safe -- use auto-increment as suggested earlier. Quote Link to comment https://forums.phpfreaks.com/topic/198578-query-insert-help/#findComment-1043723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.