?
Solved

Hiding all But First Instance of Duplicate Values in a Column

Posted on 2007-03-20
3
Medium Priority
?
232 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
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 71

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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

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.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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.
Suggested Courses

864 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