Hi Friends,
I have relation Many-to-Many between [class] table and [student] table which is [class student]
[class student] have the primary key of [class] and [student]
now i want to select from table students first_name,last_name given class_id
i mean i want to select the first_name and the last_name of the student that register in that class which have the given class_id
Loading
younis abdeljawwadPosted May 28, 2012, 4:29 PM
i have table student that have information about the students
i have table class which is the section of the courses,for example if i have course name "security" and it have three classes or sections A,B,C..
in class table i have the primary key of the course table
now the relation between the students and the classes is many to many (many students in the classes,the student may have many classes)
now i want to select student names that is register in any class i select from combobox for example
i want to select all of them and then add them to listbox
i think that i the idea is now clear
thx.
Satyapriya NayakPosted May 28, 2012, 4:05 PM
Create table student(class_id varchar(255),fisrt_name varchar(255),last_name varchar(255))
class_id first_name last_name
1 raj kumar
1 ravi kumar
2 harry potter
3 ian smith
Create table class(class_id varchar(255),class_name varchar(255))
class_id class_name
1 a
2 b
3 c
Query
SELECT s.first_name, s.last_name, c.class_name
FROM student AS s INNER JOIN
class AS c ON s.class_id = c.class_id
WHERE (s.class_id = '3')
Output
first_name last_name class_name
ian smith c
Thanks