This the name of my table Result_Simul
This is the value
Pk FkIdResult FkIdSimul
1 43 1244
2 43 1244
3 52 1244
4 52 1244
How to keep just keep rows Pk=1 and Pk=3 and delete Pk=2 and Pk=4
Thanks for helping me.
Im not really good in Tsql
Frank
➤ From the Remove Rows option under the Home tab, click on Remove Duplicates. Step 4: ➤ The duplicate rows will be removed keeping the first rows.
You can use row_number
to give each duplicate an ascending number, and then delete the 2nd and higher duplicates:
delete tbl
from (
select row_number() over (partition by FkIdResult, FkIdSimul
order by Pk desc) as rn
, *
from YourTable
) tbl
where rn > 1
Working example at SE Data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With