Click here to Skip to main content
15,920,687 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
difference between count(1) and count(*) with example.

What I have tried:

difference between count(1) and count(*) with example
Updated 7-May-18 5:05am
Christiaan van Bergen 2-Apr-18 8:48am    
Dude, really?*)

There used to be a time when it was relevant what you had inside COUNT or what expression you used in an EXISTS structure.

In the old ages the optimizer wasn't necessarily smart enough to eliminate the row retrieval if a column was used in such expression. This caused an unnecessary disk or memory I/O operation to the table when the data itself was irrelevant to the query.

However, this was a time just before dinosaurs were extinct so any modern optimizer recognizes this situation and understands not to fetch the actual record. I could imagine there are some database products that are in their early stages and suffer from these kinds of problems but if we're talking about the mainstream databases then the answer is easy: No difference.
Share this answer
no existe una diferencia entre estos dos tipos de consultas

select count(*) y count(1) => son iguales, es decir si tenemos una tabla con 5 registros en los dos casos nos va dar 5.

create table #tabla (student varchar(50), id int)
insert into #table (student,id)

select count(*) from #tabla
-- result 5

select count(1) from #tabla 
-- result 5

select count(id) from #tabla
-- result 3

espero poder ayudarte...
Share this answer
Maciej Los 7-May-18 15:42pm    
In English, please...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900