2017-09-05 23:11 GMT+02:00 Simon Slavin <slav...@bigfraud.org>: > > > On 5 Sep 2017, at 9:21pm, Cecil Westerhof <cldwester...@gmail.com> wrote: > > > I want to know the number of teas I have in stock. For this I use: > > SELECT COUNT(Tea) > > FROM teaInStock > > > > Tea cannot be NULL, so this is the same as: > > SELECT COUNT(*) > > FROM teaInStock > > > > But I find the first more clear. > > I almost always see the second variant. Is this because it is more > > efficient, or are people just ‘lazy’? > > Your guess is right ! > > To do COUNT(*) SQLite has to retrieve all the rows. > To do COUNT(value) has to retrieve all the rows and test the value of each > row to make sure it is not NULL. > > Also, SQLite has a specific piece of code which makes COUNT(*) more > efficient than counting the values. However, unless you have a big > database, the difference for your case may be small. If you find > COUNT(Tea) easier to understand perhaps you should use that one. >
I will keep using COUNT(Tea) then, but keep in the back of my mind that I maybe should change that if a table becomes big. Thanks. -- Cecil Westerhof _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users