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? 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. 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 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. Link to comment https://forums.phpfreaks.com/topic/198578-query-insert-help/#findComment-1043723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.