SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 Images Attached Images

  2. #2
    SitePoint Member calflowers's Avatar
    Join Date
    Feb 2012
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you add a specific value on sr_number such as:

    SELECT sr_number=1204100002, sr_date, Items, SubItems, ItemCode, DemandedQty FROM stock_requisition;

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    what is the code to get the last inserted row on database.
    [...]
    it only display last row.. but I need to display all data with all data with same sr_number

    Why don't you explain a bit better what you need. Give an example of the result you want based on the table data you posted.

  4. #4
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post

    Why don't you explain a bit better what you need. Give an example of the result you want based on the table data you posted.
    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. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    guido, why not wait a while before answering newphpcoder's questions

    he always posts them on about a half dozen other forums, and often, as in this case, gets an answer from somewhere else
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •