SQLite - getting number of rows in a database

后端 未结 6 980
旧时难觅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:25

    Extension of VolkerK's answer, to make code a little more readable, you can use AS to reference the count, example below:

    SELECT COUNT(*) AS c from profile

    This makes for much easier reading in some frameworks, for example, i'm using Exponent's (React Native) Sqlite integration, and without the AS statement, the code is pretty ugly.

提交回复
热议问题