Henk Rensenbrink Henk Rensenbrink - 16 days ago 4x
MySQL Question

Select lead_id's where other column has duplicates as well

I have a database table looking like this:

lead_id || user_id || action_form
1 || 56 || seen
2 || 56 || sent
2 || 49 || sent
.... || .... || ....

Currently I am running the query

SELECT lead_id,
FROM creat_rg_lead_company
GROUP BY lead_id
HAVING Count(*) > 3;

which is returning all lead_id's which are present more then 3 times.
But I only want to SELECT the lead_id's which have the action_form 'sent' more then 3 times.

I want these leads to give a seperate class to hide them from other visitors.
Thanks for the assistance.


As I understand your question, you need a where statement in the query

SELECT lead_id, count(*) 
FROM creat_rg_lead_company 
WHERE action_form='sent' 
GROUP BY lead_id 
HAVING count(*) > 3;

This way you only count the numer of times the action_form is sent.

SQL Fiddle