subqueries

  • hi i have done a subqueries but but it is not displaying any records.

    select SubjectCode,SubjectName,Description

    from Subject

    Where SubjectCode In

    (select SubjectCode

    from Absence

    where SubjectCode IN

    (select SubjectCode

    from Absence

    Where SubjectCode like 'BS%' and LessonDate = '20130305'));

    Anyone can help me.

  • That's a bit convoluted, you don't need two nested subqueries

    select SubjectCode,SubjectName,Description

    from Subject

    Where SubjectCode In

    (select SubjectCode

    Where SubjectCode like 'BS%' and LessonDate = '20130305');

    That'll do the same thing.

    Does that subquery return any nulls? If so, the IN will return no matches

    http://sqlinthewild.co.za/index.php/2010/02/18/not-exists-vs-not-in/

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply