mysqljoinoperator-keywordmysql-error-1066

MySQL - More Join operators, more aliases and Error 1066


Hopefully you are going to help me again :)

Well, the problem that I have is similar to the one which I've posted yesterday, but it is extended.

We are given three tables:

Table: pfleger Pfleger

Table: station Station

Table: mitarbeiter Mitarbeiter

As states above, this problem is very similar to this problem.

What was the result? Well, I get back a table with the ID's and names of the workers who are living in Frankfurt.

Now I should additionally get back the ID'S and names of the workers who are living in Frankfurt AND working in the station called Onkologie.

How should I do this?

My code so far:

SELECT pfleger.PNR, Name
from mitarbeiter, ...
JOIN pfleger on (mitarbeiter.PNR=pfleger.PNR)
JOIN ...
where Ort='Frankfurt' and Name='Onkologie'

I don't know how to make 2nd JOIN.


Solution

  • You could try something like this

    select m.PNR, m.Name
    from Mitarbeiter m
    inner join Station s on s.PNR = m.PNR
    inner join Pfleger p on p.StationID = s.StationID
    where
      m.Ort = 'Frankfurt'
      and p.Name = 'Onkologie'