HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How do you convert IBM DB2's recursive increment to MySQL version?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
incrementyouconvertversionibmdb2recursivemysqlhow

Problem

DB2 Queries:

WITH
    TABLE1 (YEAR_END) as( VALUES
    (2011))
    ,
    TABLE2
    (YEAR_END) AS ( VALUES(2011))
    ,
    TABLE3 (YEARS) AS ( SELECT 0+2008 FROM TABLE1 T1, TABLE2 T2 
    union all
    select YEARS+1 from TABLE1 T1, TABLE2 T2, TABLE3 T3
    WHERE  YEARS < 2011
    )

select YEARS from TABLE3


Result:

2008
2009
2010
2011

how to change above DB2 statement to Mysql statement?

Solution

Recursive SQL Constructs of this nature do not exist in MySQL.

I know something like ths can be done in SQL Server 2005.

The only WITH operator in MySQL is the WITH ROLLUP modifier clause in GROUP BY functions.

Context

StackExchange Database Administrators Q#1822, answer score: 2

Revisions (0)

No revisions yet.