[Solved] SELECT from table with three foregin keys to one table [closed]


Okay, it’s Saturday night and I’m feeling mellow enough to tackle this without a data model.

You have given us the names of the three lookup tables (subjects, opinions, users) but not the actual structures and columns. So I’m making some guesses.

select subjects.name as subject_name
       , opinions.value
       , o_users.name as opinion_guy
       , p_users.name as professor
from  opinions 
      join subjects on ( opinions.subject_id = subjects.id)
      join users as o_users on ( o_users.id = opinions.opinion_guy_id)
      join users as p_users on ( p_users.id = subjects.professor_id)

/

I realize that this query almost certainly doesn’t fit your schema but it should give you some clues. Otherwise, please give us the table structures, primary and foreign keys, etc.

solved SELECT from table with three foregin keys to one table [closed]