Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting duplicates in a query.

Posted on 2008-06-26
3
Medium Priority
?
189 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 2000 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

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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 SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

704 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