By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,287 Members | 1,284 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,287 IT Pros & Developers. It's quick & easy.

how to get even or odd number rows from database in db2

P: 1
hi all,
I was trying to fetch even or odd number rows from database.
currently i am usying DB2 ver 8.0.
any one can help me out.
Jul 27 '07 #1
Share this Question
Share on Google+
1 Reply


P: 57
Pity you are not on V8.1 where the following would work (change mod()=1 to mod()=0 for even rows):

Expand|Select|Wrap|Line Numbers
  1. select *
  2.   from table(select row_number() over () as rnum, tabschema, tabname 
  3.                from syscat.tables) x
  4.  where mod(rnum,2) = 1
However, if your tables are not too large, try:

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2.   FROM (SELECT rtrim(t.tabschema) || '.' || t.tabname as key,
  3.                count(*)                               as rnum
  4.           FROM syscat.tables t,
  5.                syscat.tables t1
  6.          where rtrim(t.tabschema) || '.' || t.tabname >=
  7.                rtrim(t1.tabschema) || '.' || t1.tabname
  8.       group by rtrim(t.tabschema) || '.' || t.tabname) as x
  9.  where mod(rnum,2) = 1
Aug 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.