Bold
Bold

Reputation: 3

Inner select syntax error in sql where clause

I have two tables.

I need to join the two tables to get StudentName, FeeRate, FeeRateID for administrative purpose. I am told to join two tables to obtain the details for all students. Literary and Social Studies students’ all CourseSpecialty has to be included.

But I am asked to include Computer Science students with CourseSpecialty of Java, Python and R.

I tried this, but my code throws a syntax error. I know problem lies in the inner select (Where clause) but I'm not able to fix this on my own. Can someone help me please?

SELECT
    A.StudentName, A.StudentID, A.CourseType, B.FeeRateID
FROM
    A
LEFT JOIN
    B ON a.FeeRateId = b.FeeRateID
WHERE 
    A.CourseType IN ('Social Studies', 'Literary Studies', 'Computer Science' (SELECT CourseType FROM A WHERE CourseType = 'Computer Science' and CourseSpecialty IN ('Java', 'Python', R);

Upvotes: 0

Views: 127

Answers (1)

user8103263
user8103263

Reputation:

Don't understand why is the subquery needed in this case at all, since it will return 'Computer Science' which is already specified in the IN(...).

SELECT
    A.StudentName, A.StudentID, A.CourseType, B.FeeRateID
FROM A
    LEFT JOIN B ON a.FeeRateId = b.FeeRateID
WHERE 
    A.CourseType IN ('Social Studies', 'Literary Studies') 
    OR 
    (A.CourseType = 'Computer Science' AND A.CourseSpecialty IN ('Java', 'Python', 'R'))

Upvotes: 1

Related Questions