The first element of arrays (in most programming languages) has an id (index) of 0. The first element (row) of MySQL tables has an (auto incremented) id of 1. The latter seems to be the exception.
The first element of arrays (in most programming languages) has an id (index) of 0. The first element (row) of MySQL tables has an (auto incremented) id of 1.
Counting in SQL generally starts as "1". For instance, the substring operations count characters in a string from 1 (and not 0). row_number() enumerates rows in a group, starting from 1 (and not 0).
The COUNT(*) function returns the number of rows in a dataset using the SELECT statement. The function counts rows with NULL, duplicate, and non-NULL values. You can also use the WHERE clause to specify a condition.
MySQL COUNT() Function The COUNT() function returns the number of records returned by a select query.
The better question to ask is "why are arrays zero-indexed?" The reason has to do with pointer arithmetic. The index of an array is an offset relative to the pointer address. In C++, given array char x[5]
, the expressions x[1]
and *(x + 1)
are equivalent, given that sizeof(char) == 1
.
So auto increment fields starting at 1 make sense. There is no real correlation between arrays and these fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With