-1

我有下表:

patient: id, incidentCode, name, insurance, contactdetailsID
contactDetails: id, cityCode
lookup: id, lookupdescription
incident: id, date

患者加入联系人详细信息,例如:

inner join contactdetails on patient.contactdetailsid=contactdetails.id

患者加入事件如下:

inner join incident on patient.incidentCode=incident.id

患者加入查找如下:

inner join lookup on patient.insurance = lookup.id

和联系方式加入查找,如:

inner join lookup on contactdetails.citycode = lookup.id

现在我想从患者保险和contactdetails Citycode中同时选择Lookup.lookupDescription。我怎样才能做到这一点?在选择时,我还想要患者姓名、患者 ID、事件日期

4

2 回答 2

1

例如

SELECT
  patient.id,
  lookup.lookupdescription,
  contactDetails.cityCode
FROM patient
INNER JOIN contactdetails on patient.contactdetailsid=contactdetails.id
INNER JOIN ...
INNER JOIN ...
INNER JOIN ...
WHERE patient.id = xy

顺便说一句:JOIN你提供的最后一个对我来说似乎没有那么有意义?!看起来像是lookup.id一个城市代码,同时又是一个保险号码?!

于 2013-02-27T14:38:49.077 回答
0
SELECT  d.lookupDescription,
        a.insurance,
        e.Citycode,
        a.name,
        a.id,
        c.date
FROM    patient a
        INNER JOIN contactdetails b
            ON a.contactdetailsid = b.id
        INNER JOIN  incident c
            ON a.incidentCode = c.id
        INNER JOIN lookup d
            ON a.insurance = d.id
        INNER JOIN contactdetails e
            ON e.citycode = d.id

要进一步了解有关联接的更多信息,请访问以下链接:

于 2013-02-27T14:40:07.997 回答