[Zope] Finding out how many rows is selected in database

Thomas B. Passin tpassin@mitretek.org
Thu, 5 Apr 2001 14:17:56 -0400


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