使用来自不同表的WHERE语句从SQL Server中删除行

时间:2020-11-28 09:06:08

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

我需要根据两个表中的混合where语句从表中删除一些行。

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:

将其更改为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.

但有些事情仍然是错误的,请帮助。

1 个解决方案

#1


21  

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 

#1


21  

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