Home > Mobile >  How to get exact rows count of particular column in MySQL table
How to get exact rows count of particular column in MySQL table

Time:07-15

I want to get exact row count of specified column

Example: Table

Name            Id          Age
_______________________________
  Jon           1           30
 Merry          2           40
 William                    50
 David        

There are 4 rows in table but i want to count ID column.

I am using below query to achieve it

select count(Id) from table;

But its returning 4 and I know why it is returning 4 but I want output as 2 because there are only two rows in Id column.

How can i achieve it?

CodePudding user response:

Try this:

select count(Id) from table where id>0;

CodePudding user response:

with the help of @blabla_bingo and @Edwin Dijk finally i have achieved it by below query

select count(Id) from table where Id!="";

CodePudding user response:

if column Id's value is empty string ("") instead of NULL then use following query

SELECT COUNT(Id) FROM table WHERE Id <> ''
  • Related