Advertisement

03.15.2008 at 07:35AM PDT, ID: 23243990
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

Only show DISTINCT rows

Asked by u101440 in SQL Server 2005

Tags: , ,

I have a query on a table that I need some help on. The code is attached below for you to view.

Here is a snapshot of my data:

ARCD03      RCNO03      FNAM03      SURN03      RCDT03      LECC03      AwardGiven
1      15      William      Benjamin      0      MA      1
1      16      Maria      Gibson      0      MA      2
1      16      Steven      Thomson      0      MA      2
1      17      Steven      Marshall      0      MA      1
1      18      Monica       Hand      0      MC      1
1      19      Forrester       McKelvie      0      MA      1
1      20      James      Flynn      0      MA      1
1      20      Scott      George      0      MA      1
1      21      Graeme      Taylor      0      MA      2
1      23      Kelly      Cruikshanks      0      MA      2
1      23      Stephen      Wales      0      MA      2
1      25      James      Robertson      0      MA      1

What I'm after is for some way for the query to lookup 2 fields here ARCD03 and RCNO03 and if there is a duplicate row then only show one of them.

So the data would look more like this:

ARCD03      RCNO03      FNAM03      SURN03      RCDT03      LECC03      AwardGiven
1      15      William      Benjamin      0      MA      1
1      16      Maria      Gibson      0      MA      2
1      17      Steven      Marshall      0      MA      1
1      18      Monica       Hand      0      MC      1
1      19      Forrester       McKelvie      0      MA      1
1      20      James      Flynn      0      MA      1
1      21      Graeme      Taylor      0      MA      2
1      23      Kelly      Cruikshanks      0      MA      2
1      25      James      Robertson      0      MA      1

(The above has a 3 rows removed from it as both ARCD03 and RCNO03 data matched)

I'm currently trying this with a derived table (basically I have another View that only looks up ARCD03 and RCNO03 for DISTINCT values and then this is added as a table View in another query that brings in the other data). This appear s to work but takes a very long time to execute probably due to the compexity of the problem I've handed it.

Any ideas how to simplify is appreciated.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
SELECT DISTINCT 
                      TOP (100) PERCENT dbo.Ptp03.ARCD03, dbo.Ptp03.RCNO03, dbo.Ptp03.FNAM03, dbo.Ptp03.SNAM03, dbo.Ptp03.RCDT03, dbo.Ptp03.LECC03, 
                      MAX(dbo.Ptp06.AWNO06) AS AwardGiven
FROM         dbo.Ptp03 LEFT OUTER JOIN
                      dbo.Ptp06 ON dbo.Ptp03.ARCD03 = dbo.Ptp06.ARCD06 AND dbo.Ptp03.RGNO03 = dbo.Ptp06.RGNO06
GROUP BY dbo.Ptp03.ARCD03, dbo.Ptp03.FNAM03, dbo.Ptp03.SNAM03, dbo.Ptp03.RCDT03, dbo.Ptp03.LECC03, dbo.Ptp03.RCNO03
HAVING      (dbo.Ptp03.ARCD03 IS NOT NULL) AND (MAX(dbo.Ptp06.AWNO06) IS NOT NULL)
ORDER BY dbo.Ptp03.ARCD03, dbo.Ptp03.RCNO03
[+][-]03.15.2008 at 07:36AM PDT, ID: 21132640

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.15.2008 at 07:39AM PDT, ID: 21132645

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.15.2008 at 07:58AM PDT, ID: 21132822

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Tags: microsoft, sql server, 2005
Sign Up Now!
Solution Provided By: chapmandew
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628