When you
sort by a column using ORDER BY, the default order is in ascending values. You
can specify the column or columns you want to sort by name. Or you could use
the ordinal position in the ORDER BY, which refers to the position of the
column in the SELECT clause. Thus if you ORDER BY 1, you are telling SQL Server
to order by the first column in the SELECT clause.
In the case
of NULLs, they come before non-NULL values in the ORDER BY. Instead of sorting,
you can choose to get a subset of query results with TOP. If you pass in a
number x, that means you want just x number of rows. You could also specify
TOP(p) PERCENT, and that gives you a percentage of records back from the whole
query results. You can also specify TOP(x) WITH TIES, which means you get at
least x number of rows. You might also get extra rows in case some of those top
values have duplicates.
You can also jump down and get some rows in the
middle/end of the query result set. You do this with OFFSET(n) ROWS. That will
skip n rows in the results and output the rest. Or you could couple it with FETCH
NEXT m ROWS ONLY. That will skip the n rows, and then give you the next m rows
in the query results.