views:

29

answers:

2

My query is:

SELECT DISTINCT IncidentStatus.IncidentStatusName, Incident.IncidentID AS Bob
FROM            Incident 
INNER JOIN      IncidentMember 
                 ON Incident.IncidentID = IncidentMember.IncidentId
INNER JOIN      IncidentStatus 
                 ON Incident.IncidentStatusID = IncidentStatus.IncidentStatusID
WHERE        (IncidentMember.MemberId = 6)

And the result is:

IncidentStatusName   Bob
---------------------------
Closed               9267
In Progress          9251
In Progress          9289
New                  7893
Resolved             7750

Required Result is:

IncidentStatusName   Bob
---------------------------
Closed               1
In Progress          2
New                  1
Resolved             1

Help Requested.

A: 

take your PK field, Incident.IncidentID, out of the select distinct clause

Beth
+3  A: 
SELECT IncidentStatus.IncidentStatusName, COUNT(Incident.IncidentID) AS Bob  
  FROM Incident 
INNER JOIN IncidentMember ON Incident.IncidentID = IncidentMember.IncidentId 
INNER JOIN IncidentStatus ON Incident.IncidentStatusID = IncidentStatus.IncidentStatusID 
WHERE (IncidentMember.MemberId = 6)
GROUP BY IncidentStatus.IncidentStatusName

Or maybe you need COUNT(DISTINCT Incident.IncidentID) (depends on your table structure)

a1ex07
I concede. You were faster. :) +1
kbrimington
You have to be fast around here... :)
Tom H.
Exellent. Thank You, Thank You Very Much!!!!! :) Really appreciated!!
Absar