[thelist] sql query - how to evenly distributed results

Bob Meetin ontheroad at frii.com
Sun Feb 25 20:33:49 CST 2007


mysql - 2 tables

$query = "select * from galleries, images
where galleries.gallery_id = images.image_gallery_id
and galleries.gallery_id in ('1','2')
limit 8";

this returns 8 rows which is fine but what I want to do is to evenly 
distribute 4 from each gallery, so 4 image from gallery #1 and 4 from 
gallery #2. i can easily do this but running a nested query, but just 
now i can't think how to do this in a single query, perhaps something to 
do with group by?

-bob







More information about the thelist mailing list