Jump to content

Archived

This topic is now archived and is closed to further replies.

Darkness Soul

Order By, may I filter?

Recommended Posts

Yo,

I have a col, VIP, and this one have my order method.. 'a', 'b', 'c'.

I need to, randomize the data, after, order the randomized by this vip col.. after, i want to order the 'c' row by ASC, like this idea:

    ORDER BY
      RAND() ,
      vip DESC ,
      nome_fantasia ASC ( WHERE vip = 'c' )

Some solution?

Thanks,

D.Soul

Share this post


Link to post
Share on other sites
You want ORDER BY FIELD( vip, 'C' )

Share this post


Link to post
Share on other sites
Hmmm.. thats a short one!

What I've done to solute that problem was:

[b]ORDER BY
  vip DESC ,
  IF( vip = 'V' , RAND() , IF( vip = 'S' , RAND() , nomefantasia ))[/b]

It works fine as wished! =)

D.Soul

Share this post


Link to post
Share on other sites
That's much more work for the DB to do, especially the RAND()... not ideal,IMHO.

Share this post


Link to post
Share on other sites
yeah, I know.. and this order is with a union inside the sql string.. but.. they want it, they get it.. =)

D.Soul

Share this post


Link to post
Share on other sites

×

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.