Start New Discussion within our Databases Community

So I have this line of code:

$results = mysql_query('SELECT * FROM members WHERE category1="Photographers" ORDER BY premium DESC, featured DESC, company ASC');

Everything works great, Premium members show up above featured. Featured above regular members, and they are all in alphabetical order. However I want to have featured members randomized and not in alphabetical order. I have tried RAND() but it randomizes all my members, please help.

Could you give me a code example? I keep getting the error "Incorrect usage of UNION and ORDER BY". Obviously I am using it wrong but I am not sure how.

Cutting out "featured DESC" makes the featured members get mixed with regular members and that is not what I want. What I want is to have something like this:

Premium Member
Featured Member Rand()
Normal Member Alphabetical

Thanks for your reply.

I found a solution on the web. Thanks for everyones help!

SELECT * 
FROM members 
WHERE category1="Photographers" 
ORDER BY 
    premium DESC, 
    featured DESC, 
    CASE WHEN featured = 1 THEN RAND() ELSE company END ASC
This question has already been answered. Start a new discussion instead.