SQL LEAST() function question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • henryrhenryr
    New Member
    • Jun 2007
    • 103

    SQL LEAST() function question

    Hello

    Using MySQL 5.0. I'm trying to select a set of data and somehow pick out rows with the smallest number in one of the columns.

    Example:
    [CODE=sql]
    SELECT first_name, LEAST(height)
    FROM people
    INNER JOIN heights ON name_id_pk=name _id_fk
    [/CODE]

    I know LEAST() shouldn't be used like this but is there a way to do this?

    The data in the table would be something like
    people.first_na me: heights.height:
    Henry 1.8
    Henry 1.6
    Henry 1.9
    Arthur 1.5
    John 1.8
    John 1.7

    The select query would pick out Henry (1.6), Arthur (1.5), John (1.7) as they are the smallest of each person with the same name.

    Hopefully that makes sense. Any help is much appreciated.

    Henry
    Last edited by henryrhenryr; Jul 30 '07, 04:46 PM. Reason: Making it clearer
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by henryrhenryr
    Hello

    Using MySQL 5.0. I'm trying to select a set of data and somehow pick out rows with the smallest number in one of the columns.

    Example:
    [CODE=sql]
    SELECT first_name, LEAST(height)
    FROM people
    INNER JOIN heights ON name_id_pk=name _id_fk
    [/CODE]

    I know LEAST() shouldn't be used like this but is there a way to do this?

    The data in the table would be something like
    people.first_na me: heights.height:
    Henry 1.8
    Henry 1.6
    Henry 1.9
    Arthur 1.5
    John 1.8
    John 1.7

    The select query would pick out Henry (1.6), Arthur (1.5), John (1.7) as they are the smallest of each person with the same name.

    Hopefully that makes sense. Any help is much appreciated.

    Henry
    Group by name is the thing that comes into my mind here. Have a look at it and see what you can come up with.

    Comment

    Working...