Solved

Getting duplicates in a query.

Posted on 2008-06-26
3
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server: SNAPSHOT replication to include a newly added table. 2 39
Help  needed 3 52
SQL Error - Query 6 55
SSMS Imprt data from Excel 7 38
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…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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