retrieving lowest user_id (autonumber) from table

Discussion in 'Programming' started by cool_abs87, Mar 31, 2008.

  1. #1
    Hey everyone, i just started getting into coldfusion and i would really appreciate some help, this thing has been buggin me for ages! Basically, i would like a cfquery to find the lowest number (autonumber) in my table(admin_tbl) and display it so i can later do some cfif function to it.

    Ive tried this amongst other things so far:

    <cfquery name="adminnum" datasource="cso6">
    SELECT min(user_id)
    FROM admin_tbl

    </cfquery>
    <cfoutput query="adminnum">
    #user_id#
    </cfoutput>

    Cheers for checking this out! Much appreciated!
     
    cool_abs87, Mar 31, 2008 IP
  2. dshuck

    dshuck Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:
    
    <cfquery name="adminnum" datasource="cso6">
    SELECT min(user_id) As MinUserId
    FROM admin_tbl
    </cfquery>
    
    <cfoutput>#adminnum.MinUserId#</cfoutput>
    
    Code (markup):
     
    dshuck, Mar 31, 2008 IP
  3. cpamoney

    cpamoney Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    He's right. When you use an aggregate such as min, max, count, sum, you need to give it a name by typing min(aaaa) as xyz.

    Then coldfusion will be able to look it up using xyz as the variable name
     
    cpamoney, Sep 12, 2008 IP