Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2004
    Posts
    21

    Unanswered: last value of database

    i want to get the last value of the database and the database look like this

    table name prospec
    TranID data item
    1 02/02/2004 2
    2 02/02/2004 2
    3 02/02/2004 3
    4 02/02/2004 3
    i want to get the value (4) which auto generate by itself
    i try "select TranID from prospec order by TranID desc limit 1"
    then when i run it then this error came out "incorrect syntax new 'limit' "

  2. #2
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482

    Re: last value of database

    Originally posted by mrbear
    i want to get the last value of the database and the database look like this

    table name prospec
    TranID data item
    1 02/02/2004 2
    2 02/02/2004 2
    3 02/02/2004 3
    4 02/02/2004 3
    i want to get the value (4) which auto generate by itself
    i try "select TranID from prospec order by TranID desc limit 1"
    then when i run it then this error came out "incorrect syntax new 'limit' "
    What type of database are you using?

  3. #3
    Join Date
    Mar 2004
    Posts
    21

    Re: last value of database

    Originally posted by ika
    What type of database are you using?
    i'm using sqlserver databse

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54

    Re: last value of database

    Originally posted by mrbear
    i want to get the last value of the database and the database look like this

    table name prospec
    TranID data item
    1 02/02/2004 2
    2 02/02/2004 2
    3 02/02/2004 3
    4 02/02/2004 3
    i want to get the value (4) which auto generate by itself
    i try "select TranID from prospec order by TranID desc limit 1"
    then when i run it then this error came out "incorrect syntax new 'limit' "
    For MS-SQL 7.0 or later, you probably want:
    PHP Code:
    SELECT TOP 1 TranID
       FROM prospec
       ORDER BY TranID DESC 
    You can actually get the same result much more portably by using:
    PHP Code:
    SELECT Max(TranID)
       
    FROM prospec 
    This should work on any database that supports SQL-89 or later.

    -PatP

  5. #5
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734

    Re: last value of database

    Originally posted by Pat Phelan
    For MS-SQL 7.0 or later, you probably want:
    PHP Code:
    SELECT TOP 1 TranID
       FROM prospec
       ORDER BY TranID DESC 
    You can actually get the same result much more portably by using:
    PHP Code:
    SELECT Max(TranID)
       
    FROM prospec 
    This should work on any database that supports SQL-89 or later.

    -PatP
    In SQL 7 or later, you also want:

    SELECT
    MAX(TranID)
    FROM
    prospec
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

  6. #6
    Join Date
    Mar 2004
    Posts
    21

    thanks

    thanks guys, the statment works. Thanks a million times

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002

    Re: last value of database

    Originally posted by derrickleggett
    In SQL 7 or later, you also want:

    SELECT
    MAX(TranID)
    FROM
    prospec
    also?

    isn't that what Pat said? you even quoted him!!!!!!

    and what's up with the "SQL 7 or later" qualification??

    are you saying select max(foo) from bar won't work in 6.5????

    whoa
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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