SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Order by

  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Order by

    I have a listing with properties. Right now I have ORDER BY property_price ASC. The point is, a property can be a special Offer (offer_price). if that is the case for that particular property the normal price(property_price) should not longer be counted for the ORDER BY, instead the offer_price should be the price! Is this possible?

    Thank you in advance
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code:
    ORDER BY
      CASE
         WHEN special offer THEN offer_price
         ELSE property_price
      END ASC

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    if the existence of a special offer depends on whether the offer_price is null or not null, use this --
    Code:
    ORDER BY COALESCE(offer_price,property_price)

    and some people say they don't like NULLs! crazy, i tell ya!

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


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
  •