Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    24

    Unanswered: Only want unique instances, but DISTINCT isn't working

    Hey guys, hope the collective can help me..
    In English, it gets the classes that correspond to a users wrong answers (think placement exam)

    Here's my query: (written for php)
    SELECT Response.Ques_ID, Response.Ans_ID, Answers.Ans_ID, Answers.Class_ID, Answers.Bool_Val, Class.Class_ID, Class.Class_Name
    FROM Response INNER JOIN Answers ON Response.Ans_ID=Answers.Ans_ID INNER JOIN Class ON Answers.Class_ID=Class.Class_ID
    WHERE Assess_ID=$assessID AND Bool_Val=0 ORDER BY Response.Ques_ID ASC", $connection);

    Which gives me exactly what I'm asking for:
    1: Class # 1
    2: Class # 2
    6: Class # 2
    8: Class # 1
    11: Class # 3
    12: Class # 1


    But all I really need is one instance of each (for example, only show Class 1 and Class 2 once). I've thrown in DISTINCT a few places to no avail, and unfortunately that's about the extent of my abilities (or at least I've hit a roadblock)

    Any ideas??

    Thanks in advance
    DevilsAdvocate
    ------------------------
    The elephant in the room
    ------------------------
    Ordo ab chao

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    SELECT DISTINCT Class.Class_ID
    ,  Class.Class_Name 
       FROM Response
       INNER JOIN Answers
          ON Response.Ans_ID=Answers.Ans_ID 
       INNER JOIN Class
          ON Answers.Class_ID=Class.Class_ID 
       WHERE  Assess_ID = $assessID
          AND Bool_Val = 0
       ORDER BY Response.Ques_ID ASC
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Apr 2010
    Posts
    24
    That was perfect; my many thanks.
    DevilsAdvocate
    ------------------------
    The elephant in the room
    ------------------------
    Ordo ab chao

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •