I need to count repeated rows but only show them in results if at least one of them has status = ‘new’.
______________
URL | Status
--------------
A new
A seen
B new
C seen
should echo:
___________
URL | SUM
-----------
A 2 (counts both the seen one and the new one because there is at least one nwe)
B 1
My idea is basically to count the repeated URLs and RIGHT JOIN it with the same table but only rows with Status = ‘new’ so that remaining rows disappear.
SELECT `userFlags` distinct(URL) WHERE Status = "new"
How do I add these conditions to the joining table and how is it called?
EDIT
I added Status = “new” to the query, how can I add distinct(URL) or nest the whole query on it?
SELECT userFlags.URL, COUNT( * ) AS SUM
FROM `userFlags`
RIGHT JOIN `userFlags` as u2 ON u2.Status = "new" AND userFlags.URL = u2.URL
GROUP BY u2.URL
ORDER BY SUM DESC
Try this :
Edit