Solved

Hiding all But First Instance of Duplicate Values in a Column

Posted on 2007-03-20
3
217 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 250 total points
ID: 18758338
No.  This is something you would do in your report writer or your program.
0
 
LVL 69

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
export sql results to csv 6 35
SQL Help 27 45
CPU high usage when update statistics 2 30
Deal with apostrophe in stored procedures 8 42
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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

770 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