The fact that there is no connection between courses an student is not an issue you need to know all the courses a student could take so given
student
Name CourseId
---------- ----------
Zishan 1,2,3
Ellen 2,3,4
(2 row(s) affected)
Course
courseid coursename
----------- ----------
1 java
2 C++
3 oracle
4 dot net
Courses_taken
sid cid
-------------------- -----------
zishan 1
zishan 2
(2 row(s) affected)
a cross join like this
select s.Name Studentname, c.courseid cid,c.coursename CourseNAme
from student s
cross join course c
Results in
Studentname cid CourseNAme
----------- ----------- ----------
Zishan 1 java
Zishan 2 C++
Zishan 3 oracle
Zishan 4 dot net
Ellen 1 java
Ellen 2 C++
Ellen 3 oracle
Ellen 4 dot net
Joining to courses_taken
select sc.Studentname,sc.Coursename,ct.cid
from
(
select s.Name Studentname, c.courseid cid,c.coursename CourseNAme
from student s
cross join course c
) sc
left join courses_taken ct on sc.StudentName = ct.sid and sc.cid = ct.cid
results in this
Studentname Coursename cid
----------- ---------- -----------
Zishan java 1
Zishan C++ 2
Zishan oracle NULL
Zishan dot net NULL
Ellen java NULL
Ellen C++ NULL
Ellen oracle NULL
Ellen dot net NULL
To exclude the courses taken a null where condition
select sc.Studentname,sc.Coursename,ct.cid
from
(
select s.Name Studentname, c.courseid cid,c.coursename CourseNAme
from student s
cross join course c
) sc
left join courses_taken ct on sc.StudentName = ct.sid and sc.cid = ct.cid
where ct.cid is null
Results in
Studentname Coursename cid
----------- ---------- -----------
Zishan oracle NULL
Zishan dot net NULL
Ellen java NULL
Ellen C++ NULL
Ellen oracle NULL
Ellen dot net NULL
(6 row(s) affected)
CROSS JOIN)