'SQL Server 'FETCH FIRST 1 ROWS ONLY' Invalid usage
I am trying to convert a Db2 query to SQL Server, I came across a construct I am not familiar with: FETCH FIRST 1 ROWS ONLY.
This is the query working on db2:
select * from products.series where state = 'xxx' order by id
FETCH FIRST 1 ROWS ONLY
and the error I am getting on SQL Server:
Invalid usage of the option FIRST in the FETCH statement.
I have tried replacing FIRST with NEXT which seems to be admitted in SQL Server, but with no success.
I am using SQL Sever 2014
Solution 1:[1]
Solution 2:[2]
You can use top() finction'
select top 1 * from table
Solution 3:[3]
SELECT TOP 1 * FROM (select * from products.series where state = 'xxx') as tmp ORDER BY id
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SqlZim |
| Solution 2 | |
| Solution 3 | Artem Pavlikovskyi |
