MySQL Inner Join Logic

Hi.  I have three tables in a MySQL Database.  Let's call them 'doctor', 'meeting_assign', and 'meeting'.  The 'meeting' table has an ID field and information for where the meeting will be held.  The 'doctor' table has information about the doctor.  The 'meeting_assign' table links the doctor to a specific meeting.

I need to formulate a query that gives me a list of the doctors that attend a specific meeting, and I need help with the logic.

Thanks in advance.
DennisHackerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zephyr_hex (Megan)DeveloperCommented:
Here is how to get doctors that have meetings assigned (doctor will show multiple times if more than one meeting exists):

SELECT *
FROM doctor d
INNER JOIN meeting_assign a ON a.Doctor_id = d.Id
INNER JOIN meeting m ON m.Id = a.Meeting_Id;

Open in new window


Same as above, except also show doctors with no meetings assigned.

SELECT *
FROM doctor d
LEFT OUTER JOIN meeting_assign a
    INNER JOIN meeting m ON m.Id = a.Meeting_Id
ON a.Doctor_id = d.Id;

Open in new window


Here is a SQL Fiddle demo.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.