TOP OPERATOR
We may want to have only a certain number of records returned. The keyword TOP will allow us to limit the number of rows returned. You can either set the number of rows to return or you can set a percentage. The keyword PERCENT is used to indicate a percentage of the rows needed.

SELECT TOP 5 OwnerName, OwnerAge, OwnerGender
FROM PetOwner

OUTPUT
OwnerName              OwnerAge    OwnerGender
———————-        ———–      ———–
Jon Arbuckle                   40                 M
James Jones                   50                  M
Sophia                            60                  F
John Smith                     25                  M
Emma Davis                  70                  F
(5 row(s) affected)

SELECT TOP 1 PERCENT OwnerName, OwnerAge, OwnerGender
FROM PetOwner
OUTPUT
OwnerName               OwnerAge    OwnerGender
———————–       ———–       ———–
Jon Arbuckle                     40                  M
James Jones                      50                 M
Sophia                               60                 F
John Smith                        25                 M
(4 row(s) affected)

I

Want to follow along on your own database?

Do you want to follow along with the examples?  We have created a sample database you can use to follow along and try in your own database.  Go to the download page and follow the instructions.  Have fun on the SQL trail!