测试一个表中的字段是否与另一个Access 2007中的字段匹配

时间:2012-02-22 16:34:50

标签: sql ms-access jet

SELECT Visits.KHA_ID, tblKentuckyCounties.countyName, tblHospitals.HospitalName, hospitalCounties.countyName
FROM (HospitalType INNER JOIN (hospitalCounties 
INNER JOIN 
tblHospitals ON hospitalCounties.countyID = tblHospitals.countyFK) ON HospitalType.HospitalTypeID = tblHospitals.HospitalTypeFK) 
INNER JOIN 
(tblKentuckyCounties INNER JOIN Visits ON tblKentuckyCounties.countyID = Visits.PAT_COUN) 
ON tblHospitals.Hosp_ID = Visits.HospitalID;

这是一个查询,它将返回患者来自的县,以及他们被看到的医院。工作良好。但是,如何才能使得唯一返回的结果是县的不同之处?我假设这是'where'关键字的使用位置?

1 个答案:

答案 0 :(得分:1)

假设......

  1. tblKentuckyCounties.countyName是“病人来自的县”
  2. hospitalCounties.countyName是“他们被看见的医院”的县​​
  3. ...添加一个WHERE子句......

    WHERE tblKentuckyCounties.countyName <> hospitalCounties.countyName