| Author |
Topic |
|
RichardSteele
Posting Yak Master
160 Posts |
Posted - 2007-09-11 : 12:10:20
|
| Is it possible to use a SELECT to retrieve a Next 50 set of records?Initial Query Select top 50 email from tableWhat would the Query look like to retrieve the Next 50 records? Thanks in advance. |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-11 : 12:28:48
|
I suppose you could do SELECT TOP 50 email from tableWHERE email not in (SELECT top 50 email from table) Future guru in the making. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2007-09-11 : 14:26:43
|
| If you're in SQL 2005select *from(select 'RowNumber' = row_number() OVER( order by email )from table ) awhere rownumber between 51 and 100 |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2007-09-11 : 14:28:47
|
| oopsselect *from(select email,'RowNumber' = row_number() OVER( order by email )from table ) awhere rownumber between 51 and 100 |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-09-11 : 14:34:31
|
quote: Originally posted by jimf oopsselect *from(select email,'RowNumber' = row_number() OVER( order by email )from table ) awhere rownumber between 51 and 100
If you are using SQL 2005, this is definitely the way to go. By the way, do yourself a favor -- don't put column aliases in quotes, it makes them look like string literals and makes your code harder to read, especially as it get complicated.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2007-09-11 : 14:41:50
|
| By the way, do yourself a favor -- don't put column aliases in quotes, it makes them look like string literals and makes your code harder to read, especially as it get complicated.I need to hit my hands with a ruler when I do that. It's an old bad habit that looked better to me than using <expr1> AS ColNamebut what a nightmare when someone says, "we need that to be dynamic" Jim |
 |
|
|
Kristen
Test
22859 Posts |
|
|
|