Varkaf Varkaf - 1 month ago 5
SQL Question

ORACLE Select from 3 tables

I have this problem of getting data from some tables in Oracle;
Table scheme:

STUDENTS ( ID , NAME , YEAR )

MARKS ( ID , CODE, MARK)

CLASSES ( CODE , DEFINITION , YEAR )




In STUDENTS> ID - PRIMARY KEY

IN MARKS> ID AND CODE - ARE BOTH KEYS

IN CLASSES> CODE - PRIMARY KEY

As you can see there are 3 (three) tables and i want to get all the classes that a student attends. For example John has 2 marks to only 2 classes so I want to display the name of the student and those classes he attends.

So I must connect the MARKS to CLASSES to get the Definition and then the STUDENTS table to the MARKS table.
I tried to create a subquery, but it didn't work well.

Any help?

Answer

Based on your table structures it is not exactly clear what fields you join on but you should be able to JOIN the tables similar to this:

select s.name,
  m.mark,
  c.definition
from students s
inner join marks m
  on s.id = m.id
inner join classes c
  on m.code = c.code