Results 1 to 6 of 6
  1. #1
    g.raaja is offline Member
    Join Date
    Dec 2009
    Posts
    8
    Rep Power
    0

    Default How to find latest inserted rows

    Hi,

    I am having a table where same barcodes will be inserted for a project repetetively. My problem is I want to retrieve all the barcodes for that project which are inserted latest and these barcodes are might be previously allocated or new ones or both.

    Searched google but found there is no function or predefined variable like rownum in mysql. The queries available in all the forums are using desc and limit but I cant use them as I dont know how many barcodes will be inserted for a particular project again they might be same or more or less in this case I cant use limit.

    If my table is having the following records:

    barcode insertdate projectid
    10009 2011-04-29 1
    10037 2011-05-01 1
    10444 2011-05-02 1
    10019 2011-04-30 2
    10047 2011-05-03 2
    10464 2011-05-05 3
    10009 2011-05-05 1
    10037 2011-05-07 1
    10464 2011-05-07 1
    10444 2011-05-07 1

    I want to retrieve all the records of project 1 inserted for the second time only.

    Pls help me in getting the result.

    --Regards,
    raaja. g

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    If you are entering the dates, just select the project id and the max date

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    Quote Originally Posted by g.raaja View Post

    If my table is having the following records:

    barcode insertdate projectid
    10009 2011-04-29 1
    10037 2011-05-01 1
    10444 2011-05-02 1
    10019 2011-04-30 2
    10047 2011-05-03 2
    10464 2011-05-05 3
    10009 2011-05-05 1
    10037 2011-05-07 1
    10464 2011-05-07 1
    10444 2011-05-07 1

    I want to retrieve all the records of project 1 inserted for the second time only.

    Pls help me in getting the result.

    --Regards,
    raaja. g
    OK, so does that mean you would expect back only the rows for project 1 with duplicate barcodes, and the latest date?
    So barcode 10464 will not be returned because there is only the one row?

  4. #4
    g.raaja is offline Member
    Join Date
    Dec 2009
    Posts
    8
    Rep Power
    0

    Default How to find latest inserted rows

    Hi,

    But I need all the records which are inserted latest for project 1. I dont want only the duplicates.

    --regards,
    raaja. g

  5. #5
    g.raaja is offline Member
    Join Date
    Dec 2009
    Posts
    8
    Rep Power
    0

    Default How to find latest inserted rows

    Hi,

    What I need is last entry of all the barcodes of a particular project.

    --raaja. g

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    Right.
    I needed to clarify that.
    If the above is representative of your table:
    SELECT barcode, project_id, max(insert_date)
    FROM <your_table>
    GROUP BY barcode, project_id

    If the rows have additional data that you want and you want the actual rows, then you'll have to use that as a subquery.

Similar Threads

  1. Play the latest
    By jsntg in forum New To Java
    Replies: 3
    Last Post: 10-08-2010, 04:43 AM
  2. count inserted line in database
    By tedy2808 in forum New To Java
    Replies: 3
    Last Post: 08-16-2010, 10:57 AM
  3. Replies: 2
    Last Post: 03-16-2010, 08:24 PM
  4. Replies: 0
    Last Post: 02-14-2008, 10:00 AM
  5. Replies: 2
    Last Post: 08-10-2007, 12:36 AM

Posting Permissions

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