Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select any number rows from a table without id

Author  Topic 

sqldbhl
Starting Member

3 Posts

Posted - 2009-10-13 : 05:13:52
Hello,

I have the following sql query to select rows between 200 and 300 from a table provided the table has an identity column called id:
SELECT TOP 100 * FROM TableName where id not in (select top 200 id from TableName)

I need to select rows between 200 and 300 from a table without knowing any column names.
I tried the following sql query:
SELECT TOP 100 * FROM TableName where * not in (select top 200 * from TableName)
But it didn't work.

Does any one know a solution?

Thanks in advance.

sanoj_av
Posting Yak Master

118 Posts

Posted - 2009-10-13 : 05:23:05
Select TOP 300 * from TableName
EXCEPT
Select TOP 200 * from TableName



Note: The records between 200 and 300 according to the identity column is not guaranteed as long as you do not specify the id column in the order by clause.
Go to Top of Page

sqldbhl
Starting Member

3 Posts

Posted - 2009-10-13 : 05:36:52
Thank you very much for your reply.
Go to Top of Page
   

- Advertisement -