What is the difference between the following two sql
statements
select count(*) from <tablename>
select count(col_name) from <tablename>

Answers were Sorted based on User's Feedback



What is the difference between the following two sql statements select count(*) from <tablena..

Answer / debasis

select count(*) from <tablename> returns the number of rows
in the table.

select count(col_name) from <tablename> return number
values in the column (Ignores null value in the colum). For
example if we execute the following 2 queries then

select count(*) form emp
select count(comm) form emp

The result will be
14
4

Is This Answer Correct ?    34 Yes 7 No

What is the difference between the following two sql statements select count(*) from <tablena..

Answer / kushi

for the First Qry,result is "No.of records"
for the second Qry,result is "No.of records for particular
columnname"

Is This Answer Correct ?    17 Yes 0 No

What is the difference between the following two sql statements select count(*) from <tablena..

Answer / sandeep

select count(*) from <tablename>
- return number of records from table


select count(col_name) from <tablename>
- return number of records where col_name is NOT NULL
- Null value is eliminated by an aggregate or other SET
operation.

Is This Answer Correct ?    5 Yes 0 No

What is the difference between the following two sql statements select count(*) from <tablena..

Answer / sql2000

There seem to be a problem with the solutions provided by
the above.

Both the counts should provide the same result which is the
no of rows in the table.
count (*) will result in a bigger table scan than count
(col_name) hence its advisable to use count(1) while
calculating the count for a table.

Correct me if I am wrong...:)

Is This Answer Correct ?    1 Yes 3 No

What is the difference between the following two sql statements select count(*) from <tablena..

Answer / karthik

both will be display same record count.

Is This Answer Correct ?    2 Yes 12 No

Post New Answer

More SQL Server Interview Questions

Do you know sql server 2008 introduces automatic auditing?

0 Answers  


what is difference between view and Dip.

0 Answers   IBM, L&T,


How to change the system date and time from SQL Plus Terminal ?

0 Answers   MCN Solutions,


What is the default isolation level of the sql server database?

1 Answers   Ness Technologies,


Can a function call a stored procedure in sql server?

0 Answers  






In what version of sql server were synonyms released?

0 Answers  


What is BCNF? How is it better than 2NF & 3NF?

0 Answers   Essar,


What are the differences between DDL, DML and DCL in SQL?

0 Answers   ABB, Aspire, Infogain,


What is the datatype returned by count(*)

22 Answers   247Customer, Asian CERC,


how to find number of columns in a table in sql server 2000 and 2005 also

16 Answers   Virtusa,


What is the order by used for?

0 Answers  


Write a program using SQL queries to find a unique entry in a table.

0 Answers   Tech Mahindra,


Categories