We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,619 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Left Join and inner join latter

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
2
Contributors
6
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
7
Views
Question
Answered
newbie14
Posting Pro
590 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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
pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

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.

newbie14
Posting Pro
590 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
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
pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

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.

newbie14
Posting Pro
590 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by pritaeas

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

pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

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

newbie14
Posting Pro
590 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0938 seconds using 2.69MB