Alright so I have the query
(SELECT * FROM jokes WHERE flags < 5 AND (title LIKE ? OR joke LIKE ?) ORDER BY ups DESC,downs ASC)
UNION
(SELECT * FROM jokes WHERE flags < 5 AND (title LIKE ? OR joke LIKE ?) ORDER BY ups DESC,downs ASC)
UNION
(SELECT * FROM jokes WHERE flags < 5 AND (title LIKE ? OR joke LIKE ?) ORDER BY ups DESC,downs ASC)
LIMIT 0, 30
and I will run the same thing using COUNT(*) with no limit
(SELECT COUNT(*) FROM jokes WHERE flags < 5 AND (title LIKE ? OR joke LIKE ?) ORDER BY ups DESC,downs ASC)
UNION
(SELECT COUNT(*) FROM jokes WHERE flags < 5 AND (title LIKE ? OR joke LIKE ?) ORDER BY ups DESC,downs ASC)
UNION
(SELECT COUNT(*) FROM jokes WHERE flags < 5 AND (title LIKE ? OR joke LIKE ?) ORDER BY ups DESC,downs ASC)
Essentially what I would like to do is get the count of total results(without the limit), and also get the limited list.
The problem I am having is that when I run the count query, I’m getting a bigger number than the results I get back. The reason for this I’m guessing is when I get the results back, it filters out all the overlapping rows, where as the count only counts each, as I manually have to add them.
Any ideas on how to clean up this whole process?
Also, please note that the number of select statements changes dynamically, but I was hoping there was a way to get a general count that accounts for duplicates.
Thanks.
How about this for the Count:
This should give you the unique count, and also notice that I got rid of the order by because it’s not worth calculating for a count query.