Help needed in creating a SQL statement containing four joins Please help. Given a studentID and a TagNumber i want to get the UserID related to that TagNumber. The difficult condition is that TagNumbers can be duplicate within a Users table. So we can pinpoint the exact UserID using the UserCities table as a student is linked to a school and a school is linked to a city and UserCities table have linking information for users and cities. You can assume that the given studentID:45 and TagNumber:99.

Users:

UserID, TagNumber

Students:

StudentID, SchoolID

Schools:

SchoolID, CityID

UserCities:

UserID, CityID

I have tried this so far:

select 
    u.UserID
  from
    UserCities uc  inner join School sc on uc.CityID = sc.CityID
    inner join Student st on sc.SchoolID = st.SchoolID
  where
    st.StudentID = 9
I have done it myself.

select 
    userID 
from 
    UserCities
where 
    CityID IN (select CityID 
               from school sc, student st 
               where sc.SchoolID = st.SchoolID and StudentID = 382) 
    and userID IN (select userID 
                   from users 
                   where tagNumber = 4521) ;