• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1321
  • Last Modified:

No pseudo columns in DB2

1) Like we have rownum, rowid in oracle, we do not have pseudo columns in DB2.

2) What if we want first few, last few or a range of records in between. How
   do we fetch them.

3) We can use a sequence as one column but that is not the way I would like it.

4) Please give example queries.
1 Solution
k_murli_krishnaAuthor Commented:
5) There is one specific case: Suppose from main table we can create a temporary table with extra column ID which will contain 1,2,3,4 etc. columns.

6) This we can query with range in where clause. Please give me sample example for this route.

7) More points assured for each good and valid answer.
Sorry, you are out of luck, there is no equivalent rowid or rownum function in DB2 that corresponds to the same functionality as in Oracle. This topic has been debated endlessly. Select statements are not guaranteed to be returned in the order in which they were inserted into the table.

For fetching range of records, use like, between, in, < > etc

There are sequences, identity columns, default values, timestamps and for bit data that can be used to accomplish similar functionality to the rowid function.

for temp tables the syntax is:
with t1 as (select.....),
t2 as (select...)
select .... from t1,t2

(all in one statement, notice that there is no , after last select from temp table t2

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now