schwim;11043661 wrote:What I ended up doing to get rid of the dupes was to use GROUP BY and then actually duplicate the query for the purposes of pagination. As I read more, I know that this is not a satisfactory resolution, but have not figured out how to get rid of them without doing that.
sneakyimp;11043689 wrote:
if you are using MySQL, you might consider using the FOUND_ROWS() function
(MySql) From what I read several years ago, duplicate selects were supposed to be (potentially) MUCH more efficient than the SQL_CALC_FOUND_ROWS approach. If you want a definitive up-to-date answer, you'd have to either clock the two approaches or find recent information that matches whatever MySql version you are using. Things might have changed.
The reason is (used to be?)…
that SQL_CALC_FOUND_ROWS will perform full table scans, whereas the two queries
SELECT count(*) …;
SELECT … LIMIT …;
will use index (if possible).
This means that if some query runs too slow without index, only the double query approach will benefit from it. Unless you have a sufficiently small data set, all queries will run slowly without proper indexing, which means you are likely to need the double query approach in most cases.