How to exclude first row in SQL Server 2005 Express

只愿长相守 提交于 2019-12-24 02:34:10

问题


I want to exclude the first row from displaying from a SQL Server 2005 Express database... how do I do this?

I know how to return just the top row, but how do I return all rows, except the top row


回答1:


SELECT *
FROM yourTable 
WHERE id NOT IN (
         SELECT TOP 1 id 
         FROM yourTable 
         ORDER BY yourOrderColumn)



回答2:


SELECT *
    FROM SomeTable
    WHERE id <> (SELECT MIN(id) FROM SomeTable)
    ORDER BY id



回答3:


select * from 
    (select ROW_NUMBER() over (order by productid) as RowNum, * from products) as A
where A.RowNum > 1



回答4:


When you say you don't want the top row I assume you have some kind of order by that defines which row is at the top. This sample uses the ID column to do that.

declare @T table(ID int, Col1 varchar(10))

insert into @T
select 1, 'Row 1' union all
select 2, 'Row 2' union all
select 3, 'Row 3'

select ID
from @T
where ID <> (select min(ID)
             from @T)
order by ID


来源:https://stackoverflow.com/questions/7016863/how-to-exclude-first-row-in-sql-server-2005-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!