Jump to content

Recommended Posts

I'm using the code below, which displays the most recent 15 results. I'd like to modify it so that it displays the most recent 15 results in random order. How can I achieve this within the code below without having to use another query?

SELECT mem_id,type_id,date_added,value FROM sc_coins_asset WHERE value<>'0' ORDER BY date_added DESC LIMIT 0,15

You can try this, untested. There may be more robust ways of doing this. See if others chime in.

"SELECT mem_id,type_id,date_added FROM(SELECT value FROM sc_coins_asset WHERE value<>'0' ORDER BY RAND() DESC LIMIT 0,15) u ORDER BY date_added"

Just use shuffle() in your application. There's no reason for doing this in MySQL.

 

hansford's query is incorrect, because it yields 15 random rows which are then ordered by date (the selected fields also don't match). You want the reverse order of operations. But then again, why use MySQL in the first place?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.