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

SELECT TOP w/ DISTINCT? - possible???

Status
Not open for further replies.

net123

Programmer
Oct 18, 2002
167
US
I have a huge SELECT[/red] statement where many tables are being referenced. Without going into details, my SELECT[/red] statement utilizes TOP 100[/red] for efficiency.

What I have noticed is, probably due to my usage of many types of joins (FULL, INNER, OUTER), that multiple copies of certain IDs are coming up.

I tried implementing SELECT TOP 100 DISTINCT myID[/red] but I receive an error regarding text near the word DISTINCT.

Do I need to show more of my code or the relationships via my tables?

Your assistance will be greatly appreciated.
 
select top 100 * from (select distinct myid from ....) a

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
SELECT Distinct TOP 100 myID from table1

It is probably best if you do an orderby statemetn inthe select also to make sure the records are in the order you want the top 100 from.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top