Wednesday, March 19, 2008

Deleting multiple values using a single query

We have a table called userroles with 2 columns 1. userid and 2. userroletypekey

Userid is string field containing different user ids. userroletypekey is an int field with values from 1 to 8.

Now I want to retain only a single roletypekey for a particular user and delete the rest of userroletypekeys. Frame the query of this requirement.

delete from userroles where userid = 'NBK4HKA' and userroletypekey in (1,2,4,5,6,7,8)
commit

No comments: