My ultimate goal is to select every second row (by primary key order) without any additional columns in the result set. I want to do any manipulation in dbisql but the final SELECT will be in a MobiLink script. I need to repeat this on multiple tables and can make no assumptions about the pkey values or type. I can add a column to each table if needed.
Can it be done in a single select statement (without adding a column)? (I know SELECT * FROM Foo WHERE mod(number(*),2) = 0 ORDER BY num does not work)
If I add a column to all the tables, can a single update be written to update every second column?
If the rows are inserted in primary key order, chances are adding a column with default autoincrement should number them in order and then I select every odd or even value but there is no guarantee of the order.
I'm working with SQL Anywhere 11 in this particular problem.
After messing up the syntax a few times, I got a single SELECT to work:
SELECT Ba.num, Ba.MyID FROM (SELECT num, MyID, row_number() OVER( ORDER BY num ) From Foo) AS Ba(num,MyID,bar) WHERE mod(Ba.bar,2) = 0
Still curious if a single UPDATE could be written to update every second row.
answered 23 Jun '11, 11:26