Need some php mysql help

Discussion in 'PHP' started by hope2life, Feb 3, 2010.

  1. #1
    Hi,
    I have a table in mysql database. One of the table field is named as "last".

    last
    45356
    39857
    46539

    you can see as above the column named "last" contain different values.
    I want to compare these values and get the highest value among them. I need the highest value in a variable which I want to use in a php function.
    I want to know how can this be done. Any help would be greatly appreciated.


    Thanks
     
    hope2life, Feb 3, 2010 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    SELECT `last` FROM `table_name_here` ORDER BY `last` DESC LIMIT 1
    That will select the highest value in the column
     
    JAY6390, Feb 3, 2010 IP
  3. mm10

    mm10 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    SELECT MAX(last) FROM table_name
     
    mm10, Feb 3, 2010 IP
  4. hope2life

    hope2life Active Member

    Messages:
    1,641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    90
    #4

    Excellent. This worked great.
     
    hope2life, Feb 3, 2010 IP
  5. rockjone

    rockjone Peon

    Messages:
    358
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you should use order by last ASC or DESC adjust lower and higer
     
    rockjone, Feb 3, 2010 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If the field is indexed, it doesn't matter, but if it's not, then select max() is much faster than select order by desc limit 1.
     
    SmallPotatoes, Feb 3, 2010 IP