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.

Use a UNION. First select your premiums, second the featured randomized.

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.

Just cut the "featured DESC" from your query and check the result.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.