Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql code to select distinct from one column

Author  Topic 

jharr100
Starting Member

2 Posts

Posted - 2008-11-21 : 00:09:32
I need help---

lets say my results from a query looks like this

course id description course credit instructor
151 csc class 3 smith
151 csc class 3 davis
151 csc class 3 scott
233 csc 2class 3 robinson
233 csc 2class 3 elliot
444 csc 3class 3 rogers
554 csc 4class 3 chen

so how would i only do a distinct on one column to get an output like:
course id description course credit instructor
151 csc class 3 smith
csc class 3 davis
csc class 3 scott
233 csc 2class 3 robinson
csc 2class 3 elliot
444 csc 3class 3 rogers
554 csc 4class 3 chen

Ive tried using distinct, using aggregate functions and using group by and order by and nothing gives me that exact output

PLEASE HELP!!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-21 : 00:22:23
this is just a presentation issue. Most reporting applications have property build on it. its called discard duplicates or Hide duplicates. which report application are you using?
you dont need to tweak your sql for this.
Go to Top of Page

jharr100
Starting Member

2 Posts

Posted - 2008-11-21 : 00:33:37
um I am not sure the reporting application... I am new to this... this is actually for an assignment and I have searched and searched and can't find out how
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-21 : 01:34:15
[code]SELECT CASE WHEN Seq=1 THEN CAST(courseid S varchar(10))
ELSE ''
END AS courseid,
description, course, credit, instructor
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY courseid ORDER BY instructor desc) as seq,*
FROM YourTable)t[/code]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-21 : 02:53:10
quote:
Originally posted by jharr100

um I am not sure the reporting application... I am new to this... this is actually for an assignment and I have searched and searched and can't find out how

Tell the person who assingned this task that this should be done in the presentation layer


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -