List:General Discussion« Previous MessageNext Message »
From:Jay Blanchard Date:January 27 2005 5:37pm
Subject:RE: How to select every second record
View as plain text  
[snip]
mysql> set @a:=0;
Query OK, 0 rows affected (0.00 sec)

mysql> select @a:=@a+1,mod(@a,2),ordr_ID, poft_Sub_Month from er_poft 
group by 3,4 having mod(@a,2) = 0 limit 5;
+----------+-----------+---------+----------------+
| @a:=@a+1 | mod(@a,2) | ordr_ID | poft_Sub_Month |
+----------+-----------+---------+----------------+
|        2 |         0 |    4323 | 01             |
|        4 |         0 |    4329 | 01             |
|        6 |         0 |    4332 | 01             |
|        8 |         0 |    4335 | 01             |
|       10 |         0 |    4344 | 01             |
+----------+-----------+---------+----------------+
5 rows in set (0.00 sec)
[/snip]

Now THIS is an elegant solution. The variable removes the need for an
auto-increment field. I can see that the group by might interfere with
the results if you are not careful, but using any unique identifier in
the record should work out well.

Thread
How to select every second recordMartin Rytz27 Jan
  • Re: How to select every second recordMartijn Tonies27 Jan
RE: How to select every second recordJay Blanchard27 Jan
RE: How to select every second recordJay Blanchard27 Jan
  • RE: How to select every second recordGordon27 Jan
RE: How to select every second recordJay Blanchard27 Jan