SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    Helston, Cornwall, England
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Min/Max result for each row

    Hi all,

    I have a table with the following columns: Id, Price 1, Price 2, Price 3 and so on.

    I'm happy that I can select the min/max value of each column, but is it possible to select the min/max value of prices for each row, e.g.

    ID/ Price1/ Price2/ Price3/ Price4
    1/ 100/ 150/ 400/ 250

    would return Min 100 and Max 400.

    I'm scratching my head here.
    Last edited by Ward; Aug 30, 2004 at 14:01.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,262
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    select least(price1,price2,price3) as minprice
    , greatest(price1,price2,price3) as maxprice
    from yourtable
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    Helston, Cornwall, England
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rudy and thanks, works a treat.


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
  •