使用外键过滤

时间:2012-02-16 10:06:38

标签: sql sql-server sql-server-2005

我有三个表tblClientstblClientsActivitiestblActivities

tblClientstblClientsActivities联合起来制作下面的表A

SELECT * from tblClientsActivities 
left join tblclients on tblClientsActivities.fk_cid=tblclients.pk_cid

PK_AID      FK_CID     FK_AID
1             4          1   
2             4          2
3             4          4
4             5          1
5             5          3
6             5          5
7             6          1
8             6          2
9             7          6
10            8          3

问题是如何删除所有FK_AID<>的客户端? 1

2 个答案:

答案 0 :(得分:0)

描述

简单使用WHERE子句。

示例

SELECT * FROM tblClientsActivities 
LEFT JOIN tblclients on tblClientsActivities.fk_cid=tblclients.pk_cid
WHERE FK_AID <> 1

答案 1 :(得分:0)

使用WHERE子句中使用的限制:

SELECT * from tblClientsActivities
left join tblclients on tblClientsActivities.fk_cid=tblclients.pk_cid
where FK_AID != 1