I have a table active_users and from that i want to select the rows where user_id has occurred more than 2 times and notified = 0 .Want single result only
Just count and group by user_id (and any other optional properties), together with having clause:
SELECT
user_id,
mobile,
max(last_seen) AS last_seen,
notified,
count(user_id) AS number_of_records
FROM
active_users
WHERE
notified = 0
GROUP BY
user_id,
mobile,
notified
HAVING
count(user_id) > 2
This will give you all users occurred 3 times and more into the table.
SELECT *
FROM active_users
WHERE notified = 0
GROUP BY user_id
HAVING COUNT(id) >2