I want to get the IDs of rows with the same name in a Table.
Here is an example of my table, I want to get ALL the IDs of the duplicates names of id n°1. Here are the duplicates value of id n°1 : 1, 3 and 4.
x
ID | name | size
1 | name1 | 12
2 | name3 | 13
3 | name1 | 12
4 | name1 | 12
5 | name3 | 13
6 | name4 | 18
Now this is what I want to have:
ID |
1 |
3 |
4 |
Thank you 🙂
Advertisement
Answer
A simple method uses exists
:
select t.id
from t
where exists (select 1
from t t2
where t2.name = t.name and
t2.size = t.size and
t2.id = 1
);