July 25, 2014

Select Top 1 or Top n basically returns the first n rows of data based on the sql query. Select Top 1 1 or Top n s will return the first n rows with data s depending on the sql query.

For example, the query below produces the first name and last name of the first 10 matches. This query will return first name and last name only.

  1. SELECT TOP 10 FirstName, LastName
  2.   FROM [tblUser]
  3.   where EmailAddress like 'john%'


Now, look at this query with select top 10 'test' - this will produce the same number of rows as in the previous query (same database, same condition) but the values will be 'test'.

  1. SELECT TOP 10 'test'
  2.   FROM [tblUser]
  3.   where EmailAddress like 'john%'

0 comments:

Reference: Shahed Kazi at AspNetify.com