0

Suppose this is the result of a query

  id            value
------        ---------
  10              123
  10              422
  11              441
  11              986
  12              674
  13              648

What do i need to add to the query to return all the id's which have 2 or more values associated with them. So, in that case it will only return ID 10 & 11, but i need al the records.

so the result looks like:

 id            value
------        ---------
  10              123
  10              422
  11              441
  11              986

GROUP BY won't help me because i got only 1 back.. ;-)

Thank you.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786

2 Answers2

1

Here is a simple way to do this

select * from table where id in (select id from table group by id having count(id)>1) order by id;
Utkarsh Shekhar
  • 139
  • 1
  • 8
0

You can use exists:

select t.*
from t
where exists (select 1 from t t2 where t2.id = t.id and t2.value <> t.value);
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786