Selecting Rows
-
Say if i have 100 rows, if i need top 15 rows i'll use, select top 15 * from table1 if i need from row 25 to 50, how will i select!!!!
-
Say if i have 100 rows, if i need top 15 rows i'll use, select top 15 * from table1 if i need from row 25 to 50, how will i select!!!!
You can use row_number() over the sort field of your choice as a secondary query. In the following I have 1 select gets me the currencyID and the row number and joins that query to the select of the currency table. I can then filter of the RN field in the row_number query
SELECT *
FROM Currency C
INNER JOIN
(SELECT CurrencyID, ROW_NUMBER() OVER (ORDER BY CurrencyID) RN FROM currency) R
ON R.currencyid = C.CurrencyID -- Join back to the currency table
WHERE R.RN BETWEEN 6 AND 10Never underestimate the power of human stupidity RAH
-
You can use row_number() over the sort field of your choice as a secondary query. In the following I have 1 select gets me the currencyID and the row number and joins that query to the select of the currency table. I can then filter of the RN field in the row_number query
SELECT *
FROM Currency C
INNER JOIN
(SELECT CurrencyID, ROW_NUMBER() OVER (ORDER BY CurrencyID) RN FROM currency) R
ON R.currencyid = C.CurrencyID -- Join back to the currency table
WHERE R.RN BETWEEN 6 AND 10Never underestimate the power of human stupidity RAH
thanx man...i'll try that...