DelphiFAQ Home Search:

count(*) syntax in mysql


commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

You may be surprised to find out that there is no white space allowed between count and () in mysql queries.

Also be careful on which column you perform the count. It may not be wise to use count(*) if you have a certain index defined and you have a where condition that uses this index. You might want to replace the '*' with a column name. Read more on this bug here:

// ERROR 1064 (42000): You have an error in your SQL syntax;
// check the manual that corresponds to your MySQL server version for the right
// syntax to use near '(*) from table1' at line 1
select count (*) from table1;

// the next one works:
select count(*) from table1;


2010-01-12, 08:38:43
anonymous from Indonesia  
Wow.. thanks a lot..
i'm confused when my query select count (*) is not working...
i waste time for that.
thanks a milion :) :) :)



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: