Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts

    select statement to get the all data with last sr_number save

    Hi..

    I just want to know what is the code to get the last inserted row on database.

    I tried max and last_insert_id yet it did not solve my problem

    Code:
    SELECT last_insert_id(sr_number), sr_date, Items, SubItems, ItemCode, DemandedQty FROM stock_requisition;
    it display all data from my database.

    Code:
    SELECT max(sr_number), sr_date, Items, SubItems, ItemCode, DemandedQty FROM stock_requisition;
    it only display last row.. but I need to display all data with all data with same sr_number
    for example :

    1204100002

    I attach my sample data from my database:

    Thank you so much
    Attached Thumbnails Attached Thumbnails select statement to get the all data with last sr_number save-get-last-sr_number.jpg  

  • #2
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Can you show a screenshot with the column names? When getting LAST_INSERT_ID() you're getting the ID of a single record, yet you seem to be wanting multiple records.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ShaneC View Post
    Can you show a screenshot with the column names? When getting LAST_INSERT_ID() you're getting the ID of a single record, yet you seem to be wanting multiple records.
    I attach the column names.

    I just want to get all data with sr_number that was last save

    Thank you
    Attached Thumbnails Attached Thumbnails select statement to get the all data with last sr_number save-column-name.jpg  

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    It resolved my problem:

    Code:
    SELECT sr_number, sr_date, Items, SubItems, ItemCode, DemandedQty FROM stock_requisition WHERE  sr_number = (SELECT max(sr_number) from stock_requisition)
    Thank you

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    That works, but it's more complicated than is needed.

    Try simply
    Code:
    SELECT sr_number, sr_date, Items, SubItems, ItemCode, DemandedQty 
    FROM stock_requisition
    ORDER BY sr_number DESC
    LIMIT 1
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    it also doesn't help that you waste people's time by posting your questions in multiple forums at once, you have people in this forum (and others) working on a solution for you while someone elsewhere already has given you a solution.


  •  

    Posting Permissions

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