使用 WHERE 语句从不同表中删除 SQL Server 中的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7042128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delete rows from SQL Server with WHERE statement from different tables
提问by Madam Zu Zu
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.
但还是有问题,请帮忙。
回答by HLGEM
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