• subquery syntax (2007)

    Author
    Topic
    #454124

    I am trying to write the following query:

    SELECT tblStudents.txtName, tblStudents.StudentId
    FROM tblStudents
    WHERE not exists (SELECT fidName
    FROM tblAttendance
    WHERE fidClass=7);

    This part gives me 201 records :
    SELECT tblStudents.txtName, tblStudents.StudentId FROM tblStudents

    this part gives me 99 records:
    SELECT fidName FROM tblAttendance WHERE fidClass=7

    How do i put it together to get the names o the 102 people who are not in class 7
    fidname is the foreign key of studentID

    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #1126545

      Try

      SELECT tblStudents.txtName, tblStudents.StudentId
      FROM tblStudents
      WHERE tblStudents.StudentId Not In (SELECT fidName FROM tblAttendance WHERE fidClass=7);

      • #1126546

        I had tried that and I get no records even though the two parts of the query work. Still no records. attached is the back end zipped if that helps
        Thanks

        • #1126548

          I cannot open .accdb files, sorry. I don’t have Access 2007.

          • #1126551

            Sorry her it is as an mdb

            • #1126554

              The problem is that tblAttendance contains records with null values for fidName and/or fidClass. You should remove those and make the combination of fidName and fidClass the primary key of tblAttendance to prevent this from happening in the future.
              Once you have removed the incorrect records, the query returns the records you want. See attached version.

            • #1126555

              thanks. Will try to figure out whay that is true when I can think

    Viewing 0 reply threads
    Reply To: subquery syntax (2007)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: