I want to get a number of rows in my table using max(id). When it returns NULL – if there are no rows in the table – I want to return 0. And when there are rows I want to return max(id) + 1.
My rows are being numbered from 0 and autoincreased.
Here is my statement:
SELECT CASE WHEN MAX(id) != NULL THEN (MAX(id) + 1) ELSE 0 END FROM words
But it is always returning me 0. What have I done wrong?
If you want to use the MAX(id) instead of the count, after reading the comments from Pax then the following SQL will give you what you want