Reputation: 2920
There are 3 tables:
Instructor (ins_id, ins_name)
Course(c_id, c_name)
Ins_teach_course (ins_id, c_id)
ins_id
and c_id
are foreign and primary keys.
I know that all the instructors teaching courses information will be stored in ins_teach_course
, but I want to extract ins_name
and c_name
from that as well.
I have written this so far, is this correct?
select
i.ins_id, i.ins_fname, i.ins_lname, c.c_id, c.c_name
from
ins_reg i, course c
where
i.ins_id = (select ins_id from ins_teach_course)
AND c.c_id = (select c_id from ins_teach_course);
Thank you.
Upvotes: 1
Views: 561
Reputation: 3641
You need something like this:
SELECT I.ins_name, C.c_name
FROM Ins_teach_course IC
JOIN Course C ON C.c_id = IC.c_id
JOIN Instructor I ON I.ins_id = IC.ins_id
Upvotes: 0
Reputation: 311393
Your solution may retrieve uncorrelated results between instructors and courses.
In order to correlate them, you could use a join
:
SELECT i.ins_id, i.ins_name, c.c_id, c.c_name
FROM instructor i
JOIN ins_teach_course itc ON i.ins_id = itc.ins_id
JOIN course c ON c.c_id = itc.c_id
Upvotes: 1