Sajeev C Sajeev C -4 years ago 124
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

Answer Source

What you need it's the group by statement

 SELECT email, clientid 
    FROM clients 
    WHERE  status=1  
    GROUP BY email
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download