* jalil
> I need to get total number of all rows in a table and also select some
> rows from the same table. I know how to do this
> using two queries, but was wondering if there is any way to do it in one
> query (one trip to the database).

>From version 4 you can use the SQL_CALC_FOUND_ROWS option for the SELECT
statement in combination with LIMIT. You have to do a second select (SELECT
FOUND_ROWS()), but you only read the table once.

<URL: http://www.mysql.com/doc/en/SELECT.html >

In some cases the MAX-CONCAT trick can be used to get specific records in
GROUP BY queries. This could be used to get the count and for instance the
oldest row and the newest row in the same query.

<URL: http://www.mysql.com/doc/en/example-Maximum-column-group-row.html >

If SQL_CALC_FOUND_ROWS can't be used in your case, I think you are better of
doing two queries, "SELECT COUNT(*) FROM tablename" is very fast without a
WHERE clause.

<URL: http://www.mysql.com/doc/en/GROUP-BY-Functions.html#IDX1414 >

--
Roger


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to