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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using distinct with top 1

Status
Not open for further replies.

alexerm

Programmer
Feb 27, 2003
17
0
0
CA
Hi,

I want to select first 10 distinct values from the table.

If I try

SELECT TOP 10 distinct target
FROM myTable
ORDER by target

then SQL Server gives error:
"Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'distinct'."

What's wrong with this statement? I know workaround using subqueries, but is there a way to do it without subqueries?

Thanks,

Alex
 
Try reversing the order Distinct then Top 10, that worked for me.
SELECT distinct top 10 target
FROM myTable
ORDER by target
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top