467,185 Members | 1,230 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,185 developers. It's quick & easy.

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

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
  • viewed: 6132
Share:
1 Reply
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.

Similar topics

9 posts views Thread by Marius Kaizerman | last post: by
12 posts views Thread by Martin Heuckeroth | last post: by
8 posts views Thread by sqlservernewbie@yahoo.com | last post: by
1 post views Thread by COHENMARVIN@lycos.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.