Home > Mobile >  Difference between count(*) and count(true) in sql?
Difference between count(*) and count(true) in sql?

Time:02-17

what is the difference between the select count(*) and select count(true)? so is there any different between the count(*) and count(true) which one should I use? can you give me situation example for each one that is better option to choose?

CodePudding user response:

The same result, it will give you total number of rows in a table

CodePudding user response:

The result of both is the same, but count(*) is slightly faster than count(true). That is because in the first case, the aggregate function has no arguments (that's what the * means in SQL), whereas in the second case the argument true is checked for NULLness, since count skips rows where the argument is NULL.

  • Related