Louis I. answered 03/15/19
Computer Science Instructor/Tutor: Real World and Academia Experienced
Hi, Kya - there are times when optimal efficiency simply doesn't matter, but you are correct - in general, you don't want to be passing (*) into COUNT to produce a record count (open or qualified).
Instead, you want to select a single field - a primary key is a good choice.
All/most tables that I've designed contain a primary key field called ID ... so I would execute a count query that looks something like this:
SELECT COUNT(id) FROM TABLE_NAME .... or
SELECT COUNT(id) FROM TABLE_NAME WHERE <some condition >
Yes, this would exec much much faster over a table that contains 100s M or Bs of records ... and BTW, the same approach applies to all RDBMs.
So you might want to become familiar with your source table's schema before you go executing a COUNT() query ... what fields make up that table? Is there a primary key? Likely ... so what's that field's name?
Good luck!
--Lou