MySQL: Select all rows from select distinct

Viewed 778

I would like to do a specific query

select distinct name 
from tablename

to remove duplicates. But this gives me only the names. From 'select distinct name from table' I would like all columns returned with one where condition:

select * 
from tablename 
where value= 1

I tried this:

select * 
from tablename 
where value = 1 and exists (select distinct name 
                            from tablename)

Unfortunately it returns the same data as:

select * 
from tablename 
where value = 1

Which means that there is a fundamental flaw in my query.

Could someone help me with my query. Thank you in advance.

2 Answers

Can you try this select field1, field2, field3 from tablename group by field2

This query will give you the id where you have duplicates:

select distinct id
from table1
group by id
having count(id)>1

and you can put

having count(id)=1

if you want to know the ones that don have duplicates

Related