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

How to choose Top 1 of all records?

Status
Not open for further replies.

Digitalcandy

IS-IT--Management
May 15, 2003
230
US
I have a table that has ~20 columns of various types such as boolean, nvarchar, and numeric. Is it possible to select the Top 1 of all records for each key?

Sample:

TravLotID(key) Gold(boolean) Status(Nvarchar)
2 1 today
2 1 today
3 0 tomorrow
3 0 tomorrow
3 0 tomorrow
4 1 next week
4 1 next week





Based on the TravLotID field, I'd like to grab the Top row of all columns, so the TravLotID doesn't duplicate.


TravLotID(key) Gold(boolean) Status(Nvarchar)
2 1 today
3 0 tomorrow
4 1 next week





Thanks.
 
If all the other fields are duplicated as in your example just group by all the fields
i.e.
SELECT TravLotID, Gold, Status
FROM MyTable
Group by TravLotID, Gold, Status


"I'm living so far beyond my income that we may almost be said to be living apart
 
I don't think I can use your method when there are boolean fields involved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top