I need to select a person's record from multiple tables, I can get the results by using two seperate states, but cannot do the same by combining them in one statement.
The tricky thing here is that both the Laboratory table and the Diary table have a foreign key referencing the MPlan table, but they do not have any relation with each other.
How can I accomplish this? I need to do that just in one single statement.
--I get 2 rows by running the codes below
SELECT *
FROM Participant p, PCASE pc, Meeting m, MPlan mp, Laboratory l
WHERE p.PartID=pc.PartID
AND pc.PCaseNo=m.PCaseNo
AND (m.PCaseNo=mp.PCaseNo
AND m.MeetingNo=mp.MeetingNo)
AND mp.MPlanNo=l.MPlanNo
AND p.PartID=12345;
--I get 4 rows by running the codes below
SELECT *
FROM Participant p, PCASE pc, Meeting m, MPlan mp, Diary d
WHERE p.PartID=pc.PartID
AND pc.PCaseNo=m.PCaseNo
AND (m.PCaseNo=mp.PCaseNo
AND m.MeetingNo=mp.MeetingNo)
AND mp.MPlanNo=d.MPlanNo
AND p.PartID=12345;
--but I get 38 rows by running the below codes, apparently it is not correct
SELECT *
FROM Participant p, PCASE pc, Meeting m, MPlan mp, Laboratory l, Diary d
WHERE p.PartID=pc.PartID
AND pc.PCaseNo=m.PCaseNo
AND (m.PCaseNo=mp.PCaseNo
AND m.MeetingNo=mp.MeetingNo)
AND (mp.MPlanNo=l.MPlanNo OR mp.MPlanNo=d.MPlanNo)
AND p.PartID=12345;