In Oracle PL/SQL I was used to write:
SELECT * FROM MY_TABLE WHERE ROWNUM <= 100;
in order to fetch only the first 100 records of the table named MY_TABLE.
What could be the equivalent SELECT statement in SQL SERVER?
In Oracle PL/SQL I was used to write:
SELECT * FROM MY_TABLE WHERE ROWNUM <= 100;
in order to fetch only the first 100 records of the table named MY_TABLE.
What could be the equivalent SELECT statement in SQL SERVER?
SELECT TOP 100 * FROM TABLE
You can also filter rows by using where class
SELECT TOP 100 * FROM YOURTABLE WHERE YOURCONDITION
In SQL-Server You can Use TOP to select the no. of rows.
SELECT TOP 100 * FROM MY_TABLE
select top 100 * from tbl
column name is required or use *
In SQL Server 2012, you can use OFFSET
and FETCH
to determine which rows to return. They're documented under ORDER BY
; This makes sense since asking for 100 rows, when tables are by definition unordered, gives unpredictable results.
Similarly, if you use other's answers, re: TOP
, you should also have an ORDER BY
clause, or else it's not defined which rows will be returned.
SELECT TOP 100 * FROM MY_TABLE
Sorry if I misunderstood.
Edit: Must be faster