I have this clause:
SELECT count(*) FROM imagetags
INNER JOIN userimages ON imagetags.imageid = userimages.id
WHERE privacy='public'
&& (tag='cars' || description LIKE '%cars%' || title LIKE '%cars%')
GROUP BY imageid
I want to search all possible places (tag, description, title) from the two tables (imagetags, userimages) for ‘cars’, and return the number of images (essentially, the rows) that result them.
The problem is, count returns duplicate results if there is a success in two or more of those places. Eg. if there is cars in tag and description of same picture, count=2 instead of 1.
That doesn’t happen if I do SELECT imageid(…). It seems to me that GROUP BY isn’t working as it should with count, any suggestions?
Use
DISTINCTin your query:Documentation for
COUNT