SELECT COUNT(*)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

SELECT COUNT(*)

Post by Luke »

Is a query like this:

Code: Select all

SELECT COUNT( * ) AS count
FROM `table`
WHERE `email` LIKE 'Ploo%';
faster than a query like this?

Code: Select all

SELECT *
FROM `table`
WHERE `email` LIKE 'Ploo%'
If so why? Wouldn't it still have to look through the same amount of records? Thanks.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Wouldn't it still have to look through the same amount of records?
It would. But it wouldn't send them to client.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Even better with large tables is to limit the result

Code: Select all

SELECT COUNT(table_id) FROM tablename
. You should, if the table has a large number of columns notice quite a difference.
Post Reply