简体   繁体   中英

Select Statement depending on condition

How to select a particular set of records depending on Primary Key. Suppose my Primary Key is integer which are not sequential. If I specify 1023(which exists in table) then I should get the next specified number(suppose 50) records.

Can this be possible to do it?

Any Ideas?

select top 50 *
from MyTable
where MyKey > 1023
order by MyKey
Select * from [Table Name]
where primaryKey >= 1023
and primaryKey < (1023 + 50)

It depends on how you want to calculate the result set. For the simple example where you want to find the result + 50, you can do something like this:

select primaryKey+50
from [TableName]
where primaryKey=1023

If I've misunderstood your question, please let me know

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM