Click here to Skip to main content
16,021,449 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how do i delete a data from table using FIRST IN FIRST OUT (FIFO) method.i have date and ID.
using C# and SQL2008.
Posted
Comments
phil.o 29-Aug-13 11:31am    
Could you explain why you need to mix the notion of FIFO with some database delete-query ?
The database system takes care of deleting records as per the rules you give ; why on hell do you want to control the order in which records will be deleted ?
dnsserver 29-Aug-13 11:40am    
include my application first i add some items in beginning of the month.so i want to remove added item in last of the same month.(i want to firstly remove first added items).so that's why asked how to delete items using FIFO method..
thnx..
phil.o 29-Aug-13 11:46am    
You cannot control the order in which the database system will delete records.
But, you control what will be deleted with the WHERE clause. See my answer.
[no name] 29-Aug-13 11:40am    
So write a query for the first occurring date and delete it. What is the actual problem?
dnsserver 29-Aug-13 11:54am    
actual problem is i have some items.(example book,item code is 000b). so added some books book count is increase.i want to remove some books and book count is decrease remove no of books.first i want to remove first added book.that's actual i want.

You are confusing yourself! As per comments made you can do a simple delete based on either Date field or ID field.

Assuming you are inserting the records in incremental order for either of the date /ID columns, you can delete the 1st record easily.

In case you are not inserting data in incremental order in any of the fields, you should add a IDENTITY column to your table and delete data based on the value of this identity table.

Hope this helps!
 
Share this answer
 
QUOTE: include my application first i add some items in beginning of the month.so i want to remove added item in last of the same month.(i want to firstly remove first added items).so that's why asked how to delete items using FIFO method..
thnx..

Then it seems that you need, in your table, a column holding the date the record was added.
And you can delete the records with specifying this column in your WHERE clause (cannot really give a precise SQL statement as your requirement still seems a little bit obscure to me).

Start from here and come back if you have problems along the way.
 
Share this 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