Topic: i have three tables students table Have Id as a primary key Name Enrollment ,course table have Id as a primary key, Title, Code and studentcourse table have Id as a primary key studentId as a forei
i have three tables
students table Have
Id as a primary key
Name
Enrollment
,course table have
Id as a primary key,
Title,
Code
and studentcourse table have
Id as a primary key
studentId as a foreign key,
courseId as a foreign key,
i want to show all students recod which have courses
how i get these record from joining tables.
Author: SAI
PARTH
select *
from
students s
inner join
studentcourse sc
on s.Id = sc.studentId
inner join
course c
on sc.courseId = c.Id
TEJA
For best practice use a 'middle' table to avoid M to M relation between two tables.
should put 2 join statements and it should be INNER JOIN