faqts : Computers : Databases : MySQL : Language and Syntax : Queries : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 27 people (81%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Is it possible to use LIMIT and count(*) for the total number of rows?
What number of rows is returned when the LIMIT clause is used?

Jan 27th, 2000 08:39
Nathan Wallace, Jeff Fitzgerald, Paul DuBois


An example of using the LIMIT and COUNT(*) clauses together is if you
want to return 10 search results at a time but want to display the total
number of matches.

You cannot use both of these in the same query.  The COUNT(*) will
return the number of rows returned by the query after the LIMIT clause
has been applied.  So, in the example above COUNT(*) would be 10.

You need to do two separate queries, one to count the total number of
records and one to get the limited ones.