-2

I tried using limit order to get a result like

student_id | name  |  major
     1     | kate  | bio
     2     | david | chem
     3     | jake  | math

instead of

student_id | name  |  major
     1     | kate  | bio
     2     | david | chem
     3     | jake  | math
     4     |  ...  | ...
     5     |  ...  | ... 

which means 3 results instead of 5 but i got a syntax error and couldn't find solutions. any suggestions?

1 Answers1

0

SQL Server uses SELECT TOP or OFFSET/FETCH to limit rows. So, your query should look like:

select top (3) t.*
from t
order by student_id;

Note that the ORDER BY is important if you care about which rows you want. SQL tables represent unordered sets. You need an ORDER BY if you care about the ordering.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786