Get all and the last ID of database

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Get all and the last ID of database

    Newbie here. I know very little about queries. How can I find the last ID of
    a recordset? The only solution I found was the following, and while it works,
    I can't seem to figure out how to have both it and a 'get all' in the same
    query. SO - in the end, I currently have the following TWO queries, and I'm
    assuming there's a better way to do this since they're both coming from the
    same database. I need the last ID for an indexed cfloop. The database is
    currently MS Access. <cfquery name='all' datasource='month'> SELECT * FROM
    month </cfquery> <cfquery name='all_count' datasource='month'> SELECT
    Count(*) as LastID FROM month </cfquery>

    midimidi Guest

  2. Similar Questions and Discussions

    1. MySQL Database not retrieving the full database
      Hi, I am using MySQL and PHP for my repository. It has 500+ records. till now it was displayiing all records in the database, but since from one...
    2. Import Data from flat-database to relational-database
      Before I start I need some tips and pleas excuse my bad english. I have two databases, one is flat and one is a relational database. example ...
    3. NEWBIE HELP Import Data from flat-database to relational-database
      I want to import Data from a simple Database, which contains all Information in one big record into a relational Database and split up the big...
    4. Passing database info to page allow user input then pass into another database
      Hi I really am going crazy! I'm using VBScript, ASP, and SQL My page reminds me of a shopping cart but looking at shopping cart examples has not...
    5. Another user has modified the contents of this table or view; the database row you are modifying no longer exists in the database;
      Hi, I am testing a trigger that and I am getting this error message saying "Another user has modified the contents of this table or view; the...
  3. #2

    Default Re: Get all and the last ID of database

    to get the last value in any column you'd use the LAST() scalar function -
    this is a common function among database verndors. These are some other
    methods - LAST(<FIELDNAME>), MAX(<FIELDNAME>), MIN(<FIELDNAME>),
    FIRST(<FIELDNAME>), AVG(<FIELDNAME>).

    For you're example though it appears that you're using the Count(*) method
    to get the number for your to="" part of the cfloop. You can use this
    instead to="all.recordcount"

    Here are some other attributes at your disposal

    Variable name Description
    query_name.currentRow
    Current row of query that cfoutput is processing.

    query_name.columnList
    Comma-delimited list of the query columns.

    query_name.RecordCount
    Number of records (rows) returned from the query.



    Also see
    [url]http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=p art_cfm.htm[/url]


    "midimidi" <webforumsuser@macromedia.com> wrote in message
    news:cvd80i$kkr$1@forums.macromedia.com...
    > Newbie here. I know very little about queries. How can I find the last
    > ID of
    > a recordset? The only solution I found was the following, and while it
    > works,
    > I can't seem to figure out how to have both it and a 'get all' in the same
    > query. SO - in the end, I currently have the following TWO queries, and
    > I'm
    > assuming there's a better way to do this since they're both coming from
    > the
    > same database. I need the last ID for an indexed cfloop. The database is
    > currently MS Access. <cfquery name='all' datasource='month'> SELECT *
    > FROM
    > month </cfquery> <cfquery name='all_count' datasource='month'> SELECT
    > Count(*) as LastID FROM month </cfquery>
    >

    Bill Sahlas Guest

  4. #3

    Default Re: Get all and the last ID of database

    You can also query
    SELECT Max(RecordID) AS ThisMaxRecoredID FROM xxxxxx

    That will produce the last recordid as thismaxrecordid


    Steve-DDOTS Guest

  5. #4

    Default Re: Get all and the last ID of database

    Of course, 'RecordID' is your key incrementing ID for the table.
    Steve-DDOTS Guest

  6. #5

    Default Re: Get all and the last ID of database

    You can treat the resultSet as an array. To get the last value try this:

    lastVal = queryName.columnName[queryName.recordCount];


    kyle969 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139