-1

i have the tables below:

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

patient joins contactdetails like:

inner join contactdetails on patient.contactdetailsid=contactdetails.id

patient joins incident like:

inner join incident on patient.incidentCode=incident.id

patient joins lookup like:

inner join lookup on patient.insurance = lookup.id

and contact details joins lookup like:

inner join lookup on contactdetails.citycode = lookup.id

and now i want to Select both Lookup.lookupDescription from patient insurance and contactdetails Citycode. How can i do that? At select i also want patient.name, patient.id, incident.date

2 Answers2

1

For example

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

By the way: The last JOIN you provide doesn't look that meaningful to me?! It looks like lookup.id is an citycode and at the same time is an insurance number?!

Benjamin M
  • 23,599
  • 32
  • 121
  • 201
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

To further gain more knowledge about joins, kindly visit the link below:

John Woo
  • 258,903
  • 69
  • 498
  • 492