Solved

Getting duplicates in a query.

Posted on 2008-06-26
3
182 Views
Last Modified: 2012-05-05
I am trying to get a count based on unique case ID but I'm getting duplicates in a query and I'm not sure how to get unique results.  Here's my query:

SELECT
   tblcases.caseid,
   tblCases.CaseDate,
   tblCases.CaseStatus
FROM
   tblCaseSupport
INNER JOIN
   tblCases
ON
   tblCaseSupport.CaseID = tblCases.CaseID
INNER JOIN
   tblMISUsers
ON
   tblCaseSupport.UserID = tblMISUsers.UserID
INNER JOIN
   tblCustomers
ON
   tblCases.CustomerID = tblCustomers.Customerid
WHERE
   tblMISUsers.Name like '%rene%'
AND
   tblCases.CaseDate between '01/01/08' and '03/31/08'
or
   tblMISUsers.Name like '%bagl%'
AND
   tblCases.CaseDate between '01/01/08' and '03/31/08'
or
   tblMISUsers.Name like '%rodar%'
AND
   tblCases.CaseDate between '01/01/08' and '03/31/08'
ORDER BY
   tblcases.caseid asc

The problem is in some cases, two of my reps will be in the same case so those cases show up twice in my results.
0
Comment
Question by:dsabine
3 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 21878112
SELECT distinct
   tblcases.caseid,
   tblCases.CaseDate,
   tblCases.CaseStatus
FROM
   tblCaseSupport
INNER JOIN
   tblCases
ON
   tblCaseSupport.CaseID = tblCases.CaseID
INNER JOIN
   tblMISUsers
ON
   tblCaseSupport.UserID = tblMISUsers.UserID
INNER JOIN
   tblCustomers
ON
   tblCases.CustomerID = tblCustomers.Customerid
WHERE
   tblMISUsers.Name like '%rene%'
AND
   tblCases.CaseDate between '01/01/08' and '03/31/08'
or
   tblMISUsers.Name like '%bagl%'
AND
   tblCases.CaseDate between '01/01/08' and '03/31/08'
or
   tblMISUsers.Name like '%rodar%'
AND
   tblCases.CaseDate between '01/01/08' and '03/31/08'
ORDER BY
   tblcases.caseid asc
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 21878114
SELECT
   tblcases.caseid,
   MAX(tblCases.CaseDate) CaseDate,
   tblCases.CaseStatus
FROM
   tblCaseSupport
INNER JOIN
   tblCases
ON
   tblCaseSupport.CaseID = tblCases.CaseID
INNER JOIN
   tblMISUsers
ON
   tblCaseSupport.UserID = tblMISUsers.UserID
INNER JOIN
   tblCustomers
ON
   tblCases.CustomerID = tblCustomers.Customerid
WHERE
   tblMISUsers.Name like '%rene%'
AND
   tblCases.CaseDate between '01/01/08' and '03/31/08'
or
   tblMISUsers.Name like '%bagl%'
AND
   tblCases.CaseDate between '01/01/08' and '03/31/08'
or
   tblMISUsers.Name like '%rodar%'
AND
   tblCases.CaseDate between '01/01/08' and '03/31/08'
group by   tblcases.caseid,
   tblCases.CaseStatus
ORDER BY
   tblcases.caseid asc
0
 

Author Closing Comment

by:dsabine
ID: 31471147
.....Oh yeah....Distinct....not "Unique" Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now