Results 1 to 6 of 6
  1. #1
    Join Date
    May 2003
    Posts
    23

    Unhappy Unanswered: how to retrieve the largest value from a column?

    lets say a column using int as datatype

    for eg:

    the current method i used to retrieve the largest value is by...
    select TOP 1 ....from.....order by desc
    so for eg:
    let say the column contains
    10
    60
    40
    25
    40

    i will only retrieve 60. are there any loophole in the above method?

  2. #2
    Join Date
    Oct 2003
    Posts
    2

    Re: how to retrieve the largest value from a column?

    Why not try this:

    SELECT MAX(<field>) as MaxValue <from <TABLE> where <CLAUSE>

  3. #3
    Join Date
    May 2003
    Posts
    23

    Re: how to retrieve the largest value from a column?

    Originally posted by Bascy
    Why not try this:

    SELECT MAX(<field>) as MaxValue <from <TABLE> where <CLAUSE>
    Thanks.

  4. #4
    Join Date
    Oct 2003
    Location
    Pune
    Posts
    59
    TOp n gives u the number of rows.
    Max gives u the maximum value in the column
    Cyrus
    Finding ways for solution

  5. #5
    Join Date
    Oct 2003
    Posts
    2
    Originally posted by cyrus
    TOp n gives u the number of rows.
    Max gives u the maximum value in the column
    That is not quite correct...

    TOP n gives you the first n rows of the resultset, so TOP 1 is the same as MAX as long as the order is on the same field.

  6. #6
    Join Date
    Oct 2003
    Location
    Pune
    Posts
    59
    Originally posted by Bascy
    That is not quite correct...

    TOP n gives you the first n rows of the resultset, so TOP 1 is the same as MAX as long as the order is on the same field.
    i am saying the same thing without order by
    Cyrus
    Finding ways for solution

Posting Permissions

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