Skip to content
Advertisement

SQL delete except select result

I have these 3 tables, and i want to delete from all records except some already used request

  1. Registry
  2. Record
  3. Request

and i use this query which brings me all the rows i want to delete.

select *  from Record where RegistryId = 'aa6598'
except
select * from Record where Id in ( select RecordId from Request where RegistryId = 'aa6598')

How to use delete in this case?

Advertisement

Answer

delete Record where RegistryId = 'aa6598'
and Id not in ( select RecordId from Request where RegistryId = 'aa6598')
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement