Home
How It Works
Daily Challenge
Contact

Companies
Register
Login
Recruiter Tools
Post SqlAds
Resume Razor
Candidates
Register
Login
My Info
Employment
Submit Question
Training
Intro to
Informatica
Ask Mark
Recent Topics
Resume Courier
Top 10
grabowski
vlg
anjugarg
billw
jjahns
drj
nisha
nishardhini
grifman
kalaabhyas
 

Pete Russitano Design >


Yesterdays Results
86% Correct
14% Incorrect
Sponsored Jobs
IT Analyst (business analyst)
Bristol, CT
documentation, user interaction re: full sdlc responsibility. Security access, full sdlc, post-requirement.   more...
Contact Us
Project Manager (Multiple)
Windsor, CT
Junior to Senior Level Project Managers with Insurance Background   more...
Contact Us
Data Modeler
Shelton, CT
UML, Rational, RequisitePro   more...
Contact Us
Business Analyst
Windsor, CT
Insurance B/A   more...
Contact Us
Data Analyst
Shelton, CT
MSAccess, SQL Sever, SQL, DBase, Clipper, Foxpro   more...
Contact Us
Production Support Analyst - Unix, FTP
Bristol, CT
Momentum, Odin, ConnectDirect, Tidal, BARR, and Tandem application and O/S software   more...
Contact Us
Database Programming Specialist
Atlanta, GA
Advanced SQL query experience; - Five years of experience in software development; - Experience in building web-based programming applications with relational databases in a multi-tier environment   more...
Contact Us
Saiko Consulting's SqlChallenge
Saiko Consulting's SqlChallenge
CareerFactor
Saiko Consulting

Read A Topic

Return To Topics Originally Posted:  6/8/2006 7:50:35 AM
  Last Updated:  6/8/2006 7:50:35 AM

Subject:
Using TOP in a select statement

You Asked....
I understand that the TOP statement return x number of rows or x% of rows but how does SQL Server determine which rows are returned?

and we responded....
TOP is generally used in conjunction with an ORDER BY clause.

So if your SQL was:

SELECT TOP 10 * FROM Employees ORDER BY FirstName

then your result would be the first 10 "FirstName's" that are in the table.

Like I said TOP is generally used with an ORDER BY but if it is not then it is my understanding that a random resultset will be returned.

Sometimes that resultset may be the same but it is not guaranteed to always be the case.


others said.... Post Your Own Review

Review By:  Gary

>>>>>Begin Original Message<<<<<

I understand that the TOP statement return x number of rows or x% of rows but how does SQL Server determine which rows are returned?

>>>>>End Original Message<<<<<

Review On:  6/9/2006 1:49:09 AM


Review By:  Gary

>>>>>Begin Original Message<<<<<

I understand that the TOP statement return x number of rows or x% of rows but how does SQL Server determine which rows are returned?

>>>>>End Original Message<<<<<

The TOP n option in a Select statement will return n number of rows from the result set. So if you use Where or Join options it will return the first n rows from the results of that query.

If you use an Order By clause I have found it to always return the same rows it each time otherwise it is not guaranteed to return the same results.

Review On:  6/9/2006 1:54:56 AM