SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast omid020's Avatar
    Join Date
    Feb 2008
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Max() function doesn`t return maximum value

    I have such data in my table :
    rcountID(int(11))-----rcountName(varchar(255))
    1--------------------89-000011
    2--------------------89-000012
    3--------------------89-000013

    in above table rcountID is primary key and rcountNumber is unique key .
    I wrote query to get maximum value of rcountID but final result shows me all available data :

    Code:
    SELECT MAX(ym_receipt_counter.rcountID) AS maximum,
           ym_receipt_counter.rcountNumber
    From ym_receipt_counter
    GROUP BY ym_receipt_counter.rcountID;
    Code:
    also this one doesn`t work :
    SELECT MAX(ym_receipt_counter.rcountName) AS maximum,
           ym_receipt_counter.rcountID
    From ym_receipt_counter
    GROUP BY ym_receipt_counter.rcountID;
    I`m confused , what`s wrong ?

  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:
    SELECT MAX(ym_receipt_counter.rcountID) AS maximum
    FROM ym_receipt_counter

  3. #3
    SitePoint Enthusiast omid020's Avatar
    Join Date
    Feb 2008
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but I need to select both rcountID and rcountNumber .
    How can I select both of them ?

  4. #4
    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)
    Quote Originally Posted by omid020 View Post
    How can I select both of them ?
    Code:
    SELECT rcountID 
         , rcountNumber
      FROM ym_receipt_counter
    ORDER 
        BY rcountID DESC LIMIT 1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast omid020's Avatar
    Join Date
    Feb 2008
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet


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
  •