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

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

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')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.