0

I have this records in a N-N relation:

UserId DomicilioId FechaCambio Observaciones
2928BBF3-D55B-41D0-9128-95AD491CC151 6 2021-09-27 08:13:39
2928BBF3-D55B-41D0-9128-95AD491CC151 5 2021-09-24 09:34:20 Mudanza
097E8524-3784-4F63-A921-1B174AB102B4 4 2021-09-22 11:11:46 Primer Domicilio del abonado
EF1B8D25-0C44-4CC1-B5A9-D6D6ECF2831F 3 2021-09-21 11:54:48 Primer Domicilio del abonado
2928BBF3-D55B-41D0-9128-95AD491CC151 2 2021-09-18 19:46:14 Primer Domicilio del abonado
C7EE638E-1267-4511-922D-B1311D0CA32F 1 2021-09-17 22:11:20 Primer Domicilio del abonado

I need this expected output:

UserId DomicilioId FechaCambio Observaciones
2928BBF3-D55B-41D0-9128-95AD491CC151 6 2021-09-27 08:13:39
097E8524-3784-4F63-A921-1B174AB102B4 4 2021-09-22 11:11:46 Primer Domicilio del abonado
EF1B8D25-0C44-4CC1-B5A9-D6D6ECF2831F 3 2021-09-21 11:54:48 Primer Domicilio del abonado
C7EE638E-1267-4511-922D-B1311D0CA32F 1 2021-09-17 22:11:20 Primer Domicilio del abonado

Basically I need to remove the duplicate rows where UserId is equal. I have tried using DISTINCT and GROUP BY but none of them worked so far.

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • which one to keep from two duplicates of each other? – Salman A Sep 27 '21 at 11:55
  • *I have this records in a N-N relation:* And what is "N-N related" in your data? *I need to remove the duplicate rows where UserId is equal.* What row must be saved? what is precise criteria? – Akina Sep 27 '21 at 11:55
  • These records are not duplicates, just record multiple transaction per user id. Based on the logic derived from the two sample tables, you want to keep the latest version of records per user. – Shadow Sep 27 '21 at 11:58
  • I need to bring all the records at the same time, not with user id – Francisco Jarma Sep 27 '21 at 12:28

0 Answers0