SQL Server selecting the Row of table Except the First one

tktrz96b  于 2023-06-04  发布在  其他
关注(0)|答案(4)|浏览(165)

i want to select all the row except the Top One so can anybody help me on this Query.

sqserrrh

sqserrrh1#

with cte as
(
    select *, row_number() over (order by CustomerId) RowNumber
    from Sales.Customer
)
select *
from cte
where RowNumber != 1

OR

select *
from
(
    select *, row_number() over (order by CustomerId) RowNumber
    from Sales.Customer
) tt
where RowNumber != 1
avwztpqn

avwztpqn2#

In SQL Server 2012, you can do this:

select * from TableName order by Id offset 1 rows
gojuced7

gojuced73#

SELECT * FROM table1
EXCEPT SELECT TOP 1 * FROM table1
uqdfh47h

uqdfh47h4#

If id attribute is known than we can use..

SELECT t1.* FROM table t1 LEFT JOIN (
  SELECT id
  FROM table 
  LIMIT 1
) t2 ON t1.id = t2.id
WHERE t2.id IS NULL;

相关问题