limiting a top 5 query to only 5 values

  • Thread starter Thread starter Colonel Angus
  • Start date Start date
C

Colonel Angus

I have a "top 5" values query, but when there's a tie condition, I get
more than 5 records. Is there any way I can explicitly limit the
results to 5 records?
 
Your order by clause must include a tie breaker. This usually means adding
your primary key field after your order by.
 
You can add another sort level to your query. A primary key is a good one to
ensure you "arbitrarily" select only one of the records in the tie.

SELECT TOP 5 *
FROM Table
ORDER BY ActionDate Desc, PrimaryKey
 
Back
Top