0

Hi..
i want to get all columns from tbl_class where course_id of tbl_course is equal to course_id of tbl_class more over course_id of tbl_course should be thw one who has semester = 5
brife structure of tables are:
tbl_class

class_id
course_id
class_room

tbl_course

course_id
semester

i have design this kind of querry logicaly as m not good in sql but it doesnt work it return multiple values from subquerry that is i am getting 2 course ids now i want * from tbl_class where course_id = result by subquerry

SELECT * 
FROM tbl_class 
WHERE course_id = (SELECT course_id FROM tbl_course WHERE semester = '5')

thanks

2
Contributors
2
Replies
17
Views
3 Years
Discussion Span
Last Post by rch1231
0

at last did from my own logic:) if someone can improve it would be appreciable

SELECT * 
FROM tbl_class 
RIGHT JOIN (SELECT course_id FROM tbl_course WHERE semester = '3') as New
ON tbl_class.course_id=new.course_id
0

Hello,

How about this instead which is supposed to be the right way to do the query:

    SELECT 
    tbl_class.class_id,
    tbl_class.course_id,
    tbl_class.class_room,
    tbl_course.semester
    FROM tbl_class
    inner join tbl_course on tbl_course.course_id = tbl_class.course_id 
    WHERE tbl_course.semester = '5'

Or back to your original selection change the wording to:

    SELECT *
    FROM tbl_class
    WHERE course_id IN (SELECT course_id FROM tbl_course WHERE semester = '5')
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.