Random Sort Order on 2nd Column?

The following MySQL query returns a listing of Articles for each Sub-Section of my website…


SELECT ap.ds_subsection_slug, a.slug, a.heading, a.summary, a.image
FROM article AS a
INNER JOIN article_placement AS ap
ON a.slug = ap.article_slug
WHERE ap.sd_section_slug = 'finance'
AND ap.ds_dimension_slug = 'featured-finance'
ORDER BY ap.ds_subsection_slug, a.slug

My goal is to “randomize” the order in which Articles are displayed in a given Sub-Section. (Hopefully this will encourage Users to read more Articles?!)

Is there some way in MySQL, to return a result-set first sorted alphabetically by Sub-Section, but then sorted randomly by Article??

Sincerely,

Debbie

i believe you could try RAND() as your second ORDER BY expression

I stand corrected!! :blush: (I thought I did that yesterday and it failed. Who knows?!)

Thanks!!

Okay, so a follow-up question… (And this may be more one for the PHP group…)

Ideally what I would like to do is “randomize” the order in which Articles (links) are displayed, AND I also would like to incorporate the concept of “weighting”.

For example, I want the article “Filing Dates to Remember” to show up 85% of the time COMBINED WITH “randomizing” which Articles appear in the “Tax-Season” sub-section.

How would I go about that?

My initial thought would be to add an “Article Weight” column, and then from there I’d have to incorporate that with maybe something like RAND(), but I don’t know…

Sincerely,

Debbie