Citat "Thomas B. Passin" <tpassin@mitretek.org>:
You need to get a book on SQL.
Gitte Wange wrote -
Actually I need to add a new item to my database with one number higher than the item with the highest number, e.g. if there are an item in the database with number 2 then the new one must have number 3. And if there are no items then the new one must have number 1.
Say the table is "person", and the field that has the number is "id". Then
select max(id) from person
gives you the largest one. Or you could have the database calculate the next value for you:
select 1+max(id) as next_id from person
This will return a single row that has a single cell named "next_id".
You should not just count the rows, since if you delete a row, the row count will not match the max id number.
Tom P
Damn ME ! I know that - just didn't think of it that way. Sorry! Well if you make MySQL select the next_id for you - what happens then if there are no records in the table? Will it then return 1 (if you say select max(id)+1) ??? Gitte