SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ordering by content of record

    Hi,
    I am kind of getting addicted to SPF as every question I ask always gets a quick answer... I just wish the forums covered more topics

    But let's get to my question. Let's imagine I have a database with all kinds of "monitors'" data. One of these pieces of data is the color of the monitor. Is there a way that in any search I do I can make sure the "black" monitors are always ordered first?

    Let's assume a couple things:
    1. there is a black model for every model
    2. there are all kinds of colors so that a simple "ORDER BY color ASC" will not work
    3. searches always output more than one model and the black model must appear just before the other colors of the same model

    Thanks in advance for your patience.


    Adrien
    Last edited by frodo; Nov 10, 2010 at 12:17. Reason: Added clarification

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by frodo View Post
    Is there a way that in any search I do I can make sure the "black" monitors are always ordered first?
    Yes there is, I remember seeing it more than once here in this forum. I just can't remember how
    So try a search, or wait for someone else that knows how.

    Off Topic:

    What topics do you feel the forums aren't covering?

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Guido!
    I'll try searching better.

    I would like SPF to go the next level down in the stack and start covering the L and the A in LAMP. Not that there aren't other forums doing this, but it seems the community here si fa more active than other watering holes I've found. Please bear in mind this is not meant as a complaint

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Off Topic:

    Well, we do have the server management and apache configuration forums. I don't know if they cover the L and A, I never go there myself

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, I do look like a noob now!

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    ORDER BY CASE WHEN color = 'black' THEN 'alphonse' ELSE 'gaston' END, color

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by r937 View Post
    ORDER BY CASE WHEN color = 'black' THEN 'alphonse' ELSE 'gaston' END, color

    Now I remember...

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant, thanks guido: it works perfectly.

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    you're welcome, and my name's not guido

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  10. #10
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Italy
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops, sorry

  11. #11
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    no problem, i was just kidding around

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  12. #12
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alphonse, Gaston? What ever happened to Larry, Curly and Moe? or seeing the OP's handle is Frodo what about using Gimli and Legolas or simply Frodo and Sam? :-)


    <--- They've got a Cave Troll


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •