Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinct with Orderby

Status
Not open for further replies.

livezone

MIS
Jan 17, 2003
81
CA
Hi,

If I ran the following query it gives me the month name in Alapabetical order like

SELECT Distinct useMonthName FROM dbo.Summary
Apr
Feb
Jan
Jul

I have a column name useYear and useMonth (1,2,3). I still want to use distinct MonthName but want my results to be sorted by useMonth (1,2,3) instead of alphabetical sorting.

Please help
Thanks
Shafiq


 
Add:

ORDER BY UseMonth ASC

-SQLBill

Posting advice: FAQ481-4875
 
Server: Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

And my problem is that I just need to show only one column which is MonthName
 
Does this work for you?

Code:
Select useMonthName
From   (
       SELECT Distinct useMonthName, UseMonth 
       FROM dbo.Summary 
       )
Order By useMonth

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top