I'm trying to select all even or odd rows from a table in MySQL without using the ID field. I tried this, but I suppose that it doesn't work since it's based on SQL Server: how to show only even or odd rows in sql server 2008?
Thank you all in advance.
Assuming you have a column that specifies the ordering of the table, then you can use variables to do what you want:
select t.*
from (select t.*, (@rn := @rn + 1) as seqnum
from table t cross join
(select @rn := 0) vars
order by col
) t
where mod(seqnum, 2) = 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With