Solved

Getting duplicates in a query.

Posted on 2008-06-26
3
184 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

15 Experts available now in Live!

Get 1:1 Help Now