select every other row in MySQL without depending on any ID?
In unique MySQL fashion:
select *
from (
select *
, @rn := @rn + 1 as rn
from Table1
join (select @rn := 0) i
) s
where rn mod 2 = 0 -- Use = 1 for the other set
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:
SELECT x.*
FROM (
SELECT @rownum:=@rownum+1 rownum, t.*
FROM (SELECT @rownum:=0) r, table t
) x
WHERE MOD(x.rownum, 2) = 1
Even Rows:
SELECT x.*
FROM (
SELECT @rownum:=@rownum+1 rownum, t.*
FROM (SELECT @rownum:=0) r, table t
) x
WHERE MOD(x.rownum, 2) = 0
Adapted from: MySQL row number
yes possible using temp variable
Example :
set @a := 0;
select * from car_m_city WHERE mod((@a:=@a+1), 2) = 1
Explanation :
here in sql we declare @a( set @a := 0;
) temp variable.(@a:=@a+1)
now @a
increment by 1.jsut like simple way to check odd or even
mod((@a:=@a+1), 2) = 1
for odd data
mod((@a:=@a+1), 2) = 0
for even data