Sajeev C Sajeev C - 4 months ago 11
MySQL Question

mysql- fetch values for unique email ids

The database table where I have to run this query has redundant email ids stored. Table stores

. But
is always unique as it's a primary key auto incremented field

I want to fetch all
for unique email id.

Let's say is used for 2 different users. I want to exclude one of them. Let's say FCFS. I wanna include first email and exclude the next one.

This is the query that I wrote but it doesn't give me results with unique email id.

SELECT DISTINCT (email), clientid
FROM clients
WHERE status=1


What you need it's the group by statement

 SELECT email, clientid 
    FROM clients 
    WHERE  status=1  
    GROUP BY email