MySQL: Is it possible to return a "mixed" dataset?
Posted
by Tom
on Stack Overflow
See other posts from Stack Overflow
or by Tom
Published on 2010-04-20T10:51:27Z
Indexed on
2010/04/20
10:53 UTC
Read the original article
Hit count: 217
Hi,
I'm wondering if there's some clever way in MySQL to return a "mixed/balanced" dataset according to a specific criterion?
To illustrate, let's say that there are potential results in a table that can be of Type 1 or Type 2 (i.e. a column has a value 1 or 2 for each record). Is there a clever query that would be able to directly return results alternating between 1 and 2 in sequence:
1st record is of type 1, 2nd record is of type 2, 3rd record is of type 1, 4th record is of type 2, etc...
Apologies if the question is silly, just looking for some options. Of course, I could return any data and do this in PHP, but it does add some code.
Thanks.
© Stack Overflow or respective owner