Madam Zu Zu
Madam Zu Zu

Reputation: 6605

Delete rows from SQL Server with WHERE statement from different tables

I need to delete some rows from a table, based on a mixed where statement from two tables.

I tried this:

delete from tblI t1, tblS t2 
where t2.rcode = 'ALA' and t1.sid > 5

but I get a syntax error. Please help me figure this out

Changed it to JOINS:

delete from tblI
inner join tblS
on tblI.sourceid = tblS.sourceid
where tblS.rcode = 'ALA' and tblI.sourceid > 5

but something is still wrong, please help.

Upvotes: 13

Views: 44742

Answers (1)

HLGEM
HLGEM

Reputation: 96552

You have to tell it which table to delete from.

delete t1
from tblI t1 
join tblS t2  on t1.sid = t2.sid
where t2.rcode = 'ALA' 
and  t1.sid > 5 

Upvotes: 24

Related Questions