1. Often we have requirement when we want to find out the numbers of rows present in a table.
Let’s create a dummy table with some dummy data and discuss different scenarios.
Now if you want to get count of all the row.
Select Count(*) from T3 — 3 rows
This will include the entire row which has at-least one column having not null value.
But consider a case where we want to find out the number of row which has not null value for a given column.
In that case above query will not work. In that case instead of * we need to replace the column name for which we want that value should be not null.
So, if we want the entire row in T3 which has not null value for Name column. Query is:
Select Count(Name) from T3 — 2 rows
Let’s create a dummy table with some dummy data and discuss different scenarios.
CREATE TABLE T3(ID int NOT NULL, NAME varchar(50) NULL) INSERT INTO T3 VALUES (1,’shaneesh’),(2,’krishna’),(3,null) |
Select Count(*) from T3 — 3 rows
This will include the entire row which has at-least one column having not null value.
But consider a case where we want to find out the number of row which has not null value for a given column.
In that case above query will not work. In that case instead of * we need to replace the column name for which we want that value should be not null.
So, if we want the entire row in T3 which has not null value for Name column. Query is:
Select Count(Name) from T3 — 2 rows
No comments:
Post a Comment