I want to retrieve data from 4 tables in SQL Server -
i want retrieve data 4 tables. patient
table has id
pk foreign key in other 3 tables ett
, phar
, ssc
. patient lie in 1 category. i.e patient id pt1 exists in either of 3 tables. want retrieve patient info along associated category.
my query is:
select * patient p inner join ett t on p.patient_id = t.patient_id || inner join pharmacological ph on p.patient_id = ph.patient_id
i used or
clause because want 1 inner join executing @ 1 time. not giving me results, suggestions??
....patient table has id pk foreign key in other 3 tables name: ett, phar , ssc a patient lie in 1 category. example, patient id pt1 exists in either of 3 tables.
based on statement, can join tables in table patient
using left join
since record can exist on 1 table. query below uses coalesce
returns first non-null value int list.
the thing need manually specify column names want shown on list shown below.
select a.*, coalesce(t.cola, p.cola, s.cola) cola, coalesce(t.colb, p.colb, s.colb) colb, coalesce(t.coln, p.coln, s.coln) coln patient left join ett t on a.patient_id = t.patient_id left join phar p on a.patient_id = p.patient_id left join ssc s on a.patient_id = s.patient_id
to further gain more knowledge joins, kindly visit link below:
Comments
Post a Comment