Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-10-2012, 04:24 AM   PM User | #1
newphpcoder
Regular Coder

 
Join Date: Aug 2010
Posts: 653
Thanks: 155
Thanked 0 Times in 0 Posts
newphpcoder is an unknown quantity at this point
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
Click image for larger version

Name:	get last sr_number.jpg
Views:	31
Size:	52.0 KB
ID:	11027  
newphpcoder is offline   Reply With Quote
Old 04-10-2012, 04:51 AM   PM User | #2
ShaneC
Codeasaurus Rex


 
Join Date: Jun 2008
Location: Redmond, WA
Posts: 659
Thanks: 31
Thanked 100 Times in 94 Posts
ShaneC is on a distinguished road
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
ShaneC is offline   Reply With Quote
Old 04-10-2012, 07:01 AM   PM User | #3
newphpcoder
Regular Coder

 
Join Date: Aug 2010
Posts: 653
Thanks: 155
Thanked 0 Times in 0 Posts
newphpcoder is an unknown quantity at this point
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
Click image for larger version

Name:	column name.jpg
Views:	20
Size:	54.8 KB
ID:	11029  
newphpcoder is offline   Reply With Quote
Old 04-10-2012, 07:11 AM   PM User | #4
newphpcoder
Regular Coder

 
Join Date: Aug 2010
Posts: 653
Thanks: 155
Thanked 0 Times in 0 Posts
newphpcoder is an unknown quantity at this point
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
newphpcoder is offline   Reply With Quote
Old 04-10-2012, 07:51 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,056 Times in 4,025 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 04-10-2012, 02:10 PM   PM User | #6
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
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.
guelphdad is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:12 PM.


Advertisement
Log in to turn off these ads.