Hi. I want to write a query that returns a set of rows from a table. All those rows should fulfill several requirements, as specified by the query's where clause, AND I want to get exactly 5 (or X) number of rows AND I want to set an UPDATE lock on those rows.
I don't care if those 5 rows are the first 5 rows in the table that meet the requirements in the where clause or if they are the last 5 rows. In fact, they can be ANY 5 rows in the table, if they meet the requirements. But I want that update lock and I don't want more rows than 5 to be returned from the database (for performance reasons, f.ex.).
Here's how the query could look like (but it just doesn't seem to work on DB2):
select empno from emp where deptno = 3 fetch first 5 rows only for update
The problem with this query in DB2 is that "fetch first" clauses can't be used with "for update" clauses.
Surely this is a simple and common problem for which there is a known solution for.
Any help would be greatly appreciated.
I don't care if those 5 rows are the first 5 rows in the table that meet the requirements in the where clause or if they are the last 5 rows. In fact, they can be ANY 5 rows in the table, if they meet the requirements. But I want that update lock and I don't want more rows than 5 to be returned from the database (for performance reasons, f.ex.).
Here's how the query could look like (but it just doesn't seem to work on DB2):
select empno from emp where deptno = 3 fetch first 5 rows only for update
The problem with this query in DB2 is that "fetch first" clauses can't be used with "for update" clauses.
Surely this is a simple and common problem for which there is a known solution for.
Any help would be greatly appreciated.