Tuesday, July 8, 2008

Delete the result of an inner join from a SQL table

If you want to delete the result of an inner join from a table, you just need to be redundant...

delete
from userregionlocation
from userregionlocation t

inner join @res r on r.userid=t.userid and r.region=t.region and r.location=t.location

Whatever the result set of:
select *
from userregionlocation t
inner join @res r on r.userid=t.userid and r.region=t.region and r.location=t.location

is what will be deleted from the "userregionlocation" table.