SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select max ID...

    I need to return the highest record from a database... ie. return the highest userID from a vBulletin user table.

    I tried:

    Code:
    SELECT MAX(userID) As maxID FROM user
    But it doesn't seem to work


  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind... worked out what I was doing wrong...

    Not tell you tho...I'm going to bed now!


  3. #3
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Was it:
    Code:
    SELECT userID
    FROM user
    ORDER BY userID DESC
    LIMIT 1
    or
    Code:
    SELECT userID FROM contacts WHERE userID = MAX(userID);
    or something else?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,329
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    dhtmlgod, your query should have worked

    redemption, your first query is fine (won't work anywhere except mysql, though), but your second query isn't


    rudy

  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT MAX(UserID) FROM USER
    Aaron Brazell
    Technosailor



  6. #6
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I some how managed you have SELECT written twice and I didn't notice!


  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Is there nothing similar to '@@identity' (from SQL Server) for MySQL? I find that (with MSSQL anyway), if you're doing a lot of inserts at the same time, running a 'SELECT Max' statement after the INSERT may cause you to get another record's ID number. Just curious, as I'm developing a site with a MySQL backend too, and was wondering if anything similar exists for this DB.

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,329
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)


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
  •