Solved

Hiding all But First Instance of Duplicate Values in a Column

Posted on 2007-03-20
3
221 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 250 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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 ?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

717 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