?
Solved

Hiding all But First Instance of Duplicate Values in a Column

Posted on 2007-03-20
3
Medium Priority
?
223 Views
Last Modified: 2008-07-03
I have a sql statement that reads : select rep1, prep1, owner, parcel1, created from tblprofiledata where created >= '2007-02-01' and created < '2007-03-01' order by rep1, prep1

Say it returns the following results:
rep1       prep1      owner      parcel1      created
Alpine      John A      Joe B      2345      2/1/2007
Alpine      Kara K      Max K            4897      2/4/2007
Alpine      Mandy L      Kathy S      7894      2/10/2007
Coldwell      Brandy B      Louis L      7854      2/4/2007
Faulkin      Jerry K      Tabatha S      9832      2/12/2007
Faulkin      Jerry K      Martha S      9823      2/14/2007

I would like the results to display so that only the first instance of each unique value in the rep1 and prep1 columns are displayed.  So I want the results to display something like this:

rep1       prep1      owner      parcel1      created
Alpine      John A      Joe B      2345      2/1/2007
                     Kara K      Max K           4897      2/4/2007
      Mandy L      Kathy S      7894      2/10/2007
Coldwell      Brandy B      Louis L      7854      2/4/2007
Faulkin      Jerry K      Tabatha S      9832      2/12/2007
                           Martha S      9823      2/14/2007

Is it possible to do something like that with a SQL statement?
0
Comment
Question by:ckangas7
[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 15

Accepted Solution

by:
DonKronos earned 1000 total points
ID: 18758338
No.  This is something you would do in your report writer or your program.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 18758344
One way: You decide which value for the other columns should be displayed. With that, you can use something like:

select rep1, prep1, min(owner), min(parcel1), min(created) from tblprofiledata
where reated >= '2007-02-01' and created < '2007-03-01'
group by rep1, prep1
order by rep1, prep1;
0
 

Author Comment

by:ckangas7
ID: 18758685
The min statement won't quite do what I need it to, but thanks.  Will have to look into other options.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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

765 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