SQL SELECT TOP question

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

I need to select the Top 50 records from a table of over 10,000 records and
all is working just fine, but I have a what if question.

What if the 50th record's value matches the 51st record (and possible the
52nd and so on)? Does the Select Command also include those records or no?
If not, how is the 50th record determined?

Thanks for the information.

Brad
 
Brad said:
I need to select the Top 50 records from a table of over 10,000
records and all is working just fine, but I have a what if question.

What if the 50th record's value matches the 51st record ... ?

"Top 50" is perhaps a misnomer - it should more accurately be "First 50".

Your database will return the first 50 records contained in the data set
and nothing more, regardless of value.

HTH,
Phill W.
 
Phill,

Thank you for the explaination.

Is there a way to grab those other few records that might match the 50th
value? Is there special syntax in the SQL statement or is this a programming
issue?

Thanks again.

Brad
 
TOP n [PERCENT]

Specifies that only the first n rows are to be output from the query result
set. n is an integer between 0 and 4294967295. If PERCENT is also specified,
only the first n percent of the rows are output from the result set. When
specified with PERCENT, n must be an integer between 0 and 100.

If the query includes an ORDER BY clause, the first n rows (or n percent of
rows) ordered by the ORDER BY clause are output. If the query has no ORDER
BY clause, the order of the rows is arbitrary.

chanmm
 
This would have to be done in a Stored Procedure or Client side.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top