Considering following table that doesn't have any primary key, can I select every other row?
col1 col2
2 a
1 b
3 c
12 g
first select must find: 2, 3
second select must find: 1, 12
is that possible?
Considering following table that doesn't have any primary key, can I select every other row?
col1 col2
2 a
1 b
3 c
12 g
first select must find: 2, 3
second select must find: 1, 12
is that possible?
This works for me.
You can use mod 1 for odd or mod 0 for even rows
In unique MySQL fashion:
Example at SQL Fiddle.
Try this. I've adapted it from the answer linked below. I tested it on SQLFiddle and it appears to work.
http://sqlfiddle.com/#!2/0bccf/28
http://sqlfiddle.com/#!2/0bccf/29
Odd Rows:
Even Rows:
Adapted from: MySQL row number
Consider this related answer: how to show only even or odd rows in sql server 2008?
It seems to be doing exactly what you want. I think this work in MySql, but of that I am not sure.
doesn't work, but leaving up anyways.
SELECT @row := @row + 1 AS row, ... FROM yourtable, (SELECT @row := -1) as foo ... HAVING row % 2 = 0This should work for MySQL:
This uses % which is the MOD operator.
And here is the sample fiddle: http://sqlfiddle.com/#!2/cd31b/2