Dear All,
I got one table as the tblMasterData then I left join it with another table like this tblEventAlert. So what I want to do if there is a match between tblMasterData and tblEventAlert then for that tblEventAlert I would like to match it with tblDevice to to get the device details?

FROM tblMasterData 
LEFT JOIN tblEventAlert ON tblMasterData .eventAlertID=tblEventAlert.eventAlertID 
LEFT JOIN   tblEventAlert.deviceID=tblDevice.deviceID And tblEvent.eventAlertID>0
SELECT *
FROM tblMasterData MD, tblEventAlert EA, tblDevice D, tblEvent E
WHERE MD.eventAlertID = EA.eventAlertID
AND EA.eventAlertID = D.eventAlertID
AND D.eventAlertID = E.eventAlertID
AND E.eventAlertID > 0

Dear Pritaeas,
The problem is the tblMasterData does not have all eventAlertID for each data so I have to do left inner join. IF not I will miss other data those without the alertID.

SELECT *
FROM tblMasterData MD
LEFT JOIN tblEventAlert EA ON MD.eventAlertID = EA.eventAlertID
LEFT JOIN tblDevice D ON EA.eventAlertID = D.eventAlertID
LEFT JOIN tblEvent E ON D.eventAlertID = E.eventAlertID AND E.eventAlertID > 0

Dear Prit,
I think this LEFT JOIN tblEvent E ON D.eventAlertID = E.eventAlertID AND E.eventAlertID > 0 not necessary could solve it ready. Thank you.

Glad it works. It was hard to tell which of your queries were really needed.

Dear Prit,
Is ok I do understand thank you very much for your inside into my problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.