SQLite - getting number of rows in a database

后端 未结 6 1004
旧时难觅i
旧时难觅i 2020-12-24 00:57

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 t

6条回答
  •  青春惊慌失措
    2020-12-24 01:13

    Not sure if I understand your question, but max(id) won't give you the number of lines at all. For example if you have only one line with id = 13 (let's say you deleted the previous lines), you'll have max(id) = 13 but the number of rows is 1. The correct (and fastest) solution is to use count(). BTW if you wonder why there's a star, it's because you can count lines based on a criteria.

提交回复
热议问题