[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting Duplicate SQL Return

Posted on 2014-08-14
6
Medium Priority
?
198 Views
Last Modified: 2014-08-14
The following query is giving me double results.  How can I modify it to not do that?

SELECT ir.ParticipantID FROM IndResults ir INNER JOIN Participant p ON ir.ParticipantID = p.ParticipantID INNER JOIN PartRace pr ON ir.RaceID = pr.RaceID WHERE pr.RaceID = 386 AND ir.RaceID = 386  AND p.Gender = 'F' AND pr.Age >= 55 AND pr.Age <= 59 ORDER BY ir.EventPl

Thank you!
0
Comment
Question by:Bob Schneider
6 Comments
 
LVL 11

Accepted Solution

by:
Dany Balian earned 2000 total points
ID: 40260512
add distinct

SELECT distinct ir.ParticipantID FROM IndResults ir INNER JOIN Participant p ON ir.ParticipantID = p.ParticipantID INNER JOIN PartRace pr ON ir.RaceID = pr.RaceID WHERE pr.RaceID = 386 AND ir.RaceID = 386  AND p.Gender = 'F' AND pr.Age >= 55 AND pr.Age <= 59 ORDER BY ir.EventPl

Open in new window

0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 40260535
why do you order this distinct list of participants by results?

do you now intend to use that list as a cursor?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40260553
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 49

Expert Comment

by:PortletPaul
ID: 40260611
Apologies to all participants, I know it's closed but the answer to this will help on another.

@BobbaBuoy,

Are you SURE that's a good query?
I think there is a join condition missing (see line 8 below). PLEASE try this, and please let me know if there are still duplicates
SELECT
      ir.ParticipantID
FROM IndResults ir
      INNER JOIN Participant p
                  ON ir.ParticipantID = p.ParticipantID
      INNER JOIN PartRace pr
                  ON ir.RaceID = pr.RaceID
                  AND ir.ParticipantID = pr.ParticipantID
WHERE ir.RaceID = 386
      AND p.Gender = 'F'
      AND pr.Age >= 55
      AND pr.Age <= 59
ORDER BY
      ir.EventPl
;

Open in new window

0
 

Author Comment

by:Bob Schneider
ID: 40260914
Very helpful.  Thanks all!!!
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 40260923
did it remove the duplicates?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

872 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