Possible Duplicate:
how to select random unique records on each execution of the SQL Query
I have database of that structure:
id int
image_name varchar(200)
category_id int
There are about 200 records, id is unique, and there are about 20 categories, and my iamges are categorized between them.
Could you help me to get a query, which will give me 10 records with UNIQUE category_ids?
select DISTINCT(category),id,image_name FROM images 
  WHERE id=
    (FLOOR(RAND() * 
           (SELECT COUNT(*) FROM images )
          )
    );
                        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