I'm trying to do a JOIN like you see below. I only want records that have at least X email addresses in the property_res table. When I change the acount value from 10 to 20 for example the returned results stay at 949 records. This should decrease dramatically as there should be alot less matches where r.EmailAddress is found 20 times. Is there a limitation to using COUNT on a varchar data type? What is the best way to achieve this?
SELECT
r.FirstName AS ag_fname,
r.LastName AS ag_lname,
r.EmailAddress AS ag_email,
COUNT(r.EmailAddress) AS `acount`
FROM property_res e
LEFT JOIN ActiveAgent_Matrix r
ON e.ListAgentMLSID=r.MemberNumber
WHERE e.ListPrice >= 50000
GROUP BY r.EmailAddress
HAVING acount >=20
A sample output of the data shows a weird value for acount as I'd think it would be the count of the email address but they all are the same?
ag_fname | ag_lname | ag_email | acount
Jane | Doe1 | [email protected] | 3390
Jane | Doe3 | [email protected] | 3390
Jane | Doe4 | [email protected] | 3390
Jane | Doe5 | [email protected] | 3390
GROUP BY e.ListAgentMLSIDgroup bytogroup by r.FirstName, r.LastName, r.EmailAddressCOUNT(1)instead.