Click here to Skip to main content
16,018,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am designing web based stock control system using php and mysql.
I have two table in Database which is Receive item and issue item table
and here is the table structure
Receive tabale
Item Code Date Receive Receive number QuntityReceive.
xxx 2010-01-01 c12 10
yyy 2010-02-01 c15 20
xxx 2010-05-05 c34` 20
issue Table
ItemCode Date issue IssueNumber Quantity Issue
xxx 2010-03-03 c12 1
yyy 2010-02-01 c15 3
xxx 2010-05-05 c34` 6

and I want to issu item with FIFO Method ( first in first out Method) so please help me how to write SQL query
Posted
Updated 21-Oct-22 1:42am
v2

1 solution

Have a generated autoincrement key in your tables and lets call it "GenID". Then it's easy:

SQL
SELECT * FROM IssueTable WHERE GenID = (SELECT MIN(GenID) FROM IssueTable)


Same for the other table:
SQL
SELECT * FROM ReceiveTable WHERE GenID = (SELECT MIN(GenID) FROM ReceiveTable)


If you're done with the processing of the fetched record delete that entry from the correspoding table and have a trigger on delete make a copy of that record to some transaction history table. By selecting the record with the smallest GenID you'll alway fetch records after the FIFO pattern.

(My first thouhgt was to use DateTime, but if the records are inserted in very fast succession the precision of dateteime might not be adequate.)

Best Regards,
 
Share this answer
 
v2
Comments
Dalek Dave 24-Mar-11 10:32am    
Good Call.There is also a simple numbering system method, and always post the earlist 'Live' Number.
Manfred Rudolf Bihy 24-Mar-11 10:48am    
I thought that was what I had proposed, GenID as an autoincrement key.
Can you please explain what your mean?
fjdiewornncalwe 24-Mar-11 15:00pm    
Perfect answer. +5. I think DD is just agreeing with you rather than suggesting something different from your answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900