sql - How to delete rows from same table? -
i have table logs requests , responses. table has timestamp column , transaction type column 2 possible values: req, resp. regardless of why, have resp rows have no matching req row.
i trying delete resp rows don't have matching req row same timestamp. ideas?
what need in pseudocode is:
delete rows in table transaction type equals resp , has no matching req row same timestamp.
try this:
delete table t txtype = 'resp' , not exists (select * table timestamp = t.timestamp , txtype = 'req')
(inside of transaction can roll if fails!)
and oh yeah, chris lively below raises excellent point.. when refer "timestamp" speaking generically? or talking sql server timestamp data type guaranteed unique ?? if former, , using datetime or such, sure can't have 2 or more different requests @ exact same time ??
Comments
Post a Comment