If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Only want unique instances, but DISTINCT isn't working

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-24-10, 14:05
DevilsAdvocate DevilsAdvocate is offline
Registered User
 
Join Date: Apr 2010
Posts: 24
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
Reply With Quote
  #2 (permalink)  
Old 05-24-10, 14:14
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
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.
Reply With Quote
  #3 (permalink)  
Old 05-24-10, 14:25
DevilsAdvocate DevilsAdvocate is offline
Registered User
 
Join Date: Apr 2010
Posts: 24
That was perfect; my many thanks.
__________________
DevilsAdvocate
------------------------
The elephant in the room
------------------------
Ordo ab chao
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On