Jump to content


Photo

Order By, may I filter?


  • Please log in to reply
4 replies to this topic

#1 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 19 July 2006 - 08:01 PM

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

(If something is wrong, please tell me. I'm learning this language. Thank you)

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 19 July 2006 - 09:11 PM

You want ORDER BY FIELD( vip, 'C' )
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 20 July 2006 - 01:15 PM

Hmmm.. thats a short one!

What I've done to solute that problem was:

ORDER BY
  vip DESC ,
  IF( vip = 'V' , RAND() , IF( vip = 'S' , RAND() , nomefantasia ))


It works fine as wished! =)

D.Soul
(If something is wrong, please tell me. I'm learning this language. Thank you)

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 July 2006 - 04:07 PM

That's much more work for the DB to do, especially the RAND()... not ideal,IMHO.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 20 July 2006 - 08:34 PM

yeah, I know.. and this order is with a union inside the sql string.. but.. they want it, they get it.. =)

D.Soul
(If something is wrong, please tell me. I'm learning this language. Thank you)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users