Ask a Question related to MySQL, Design and Development.
-
Alan Williamson #1
How do I keep a fixed list of rows in a table?
Probably not making myself clear with that subject. Here is what I
want to do.
I want to basically implement a FIFO (FirstInFirstOut) queue in SQL.
So I want to keep adding to a given table, but only have it keep the
last say 25 items. Anything older is removed. I have been trying to
do some stuff with the DELETE statement, but I am going no where.
So say a table is setup for multiple users:
Column_User
Column_Item
Column_Date (? probably need this column)
I want there ever to be only 25 rows stored for a given user; so when I
INSERT a new item, I would need to remove/trim the items. Its this
removing of the other items that is causing me a bit grief, as I can't
seem to do it without doing another SELECT.
Thoughts? Suggestions?
Thanks
Alan Williamson Guest
-
Make certain datagrid rows fixed
Hi, If you have worked with excel, you may see that as you scroll down th rows, certain rows remain fixed but all the records move up. I needed t... -
#25473 [Opn->Bgs]: Updating single row in table causing all rows in table to be updated.
ID: 25473 Updated by: sniper@php.net Reported By: jim at bluedojo dot com -Status: Open +Status: ... -
#25473 [Opn->Fbk]: Updating single row in table causing all rows in table to be updated.
ID: 25473 Updated by: sniper@php.net Reported By: jim at bluedojo dot com -Status: Open +Status: ... -
#25473 [Opn]: Updating single row in table causing all rows in table to be updated.
ID: 25473 User updated by: jim at bluedojo dot com Reported By: jim at bluedojo dot com Status: Open Bug Type: ... -
#25473 [NEW]: Updating single row in table causing all rows in table to be updated.
From: jim at bluedojo dot com Operating system: WinXP PHP version: 4.3.3 PHP Bug Type: MySQL related Bug description: ... -
Bill Karwin #2
Re: How do I keep a fixed list of rows in a table?
Alan Williamson wrote:
MySQL implements as an extension to the SQL standard ORDER BY and LIMIT> I want there ever to be only 25 rows stored for a given user; so when I
> INSERT a new item, I would need to remove/trim the items.
clauses for the DELETE statement:
1. Start transaction
2. SELECT COUNT(*) FROM tablename WHERE column_user = 'Alan';
3. If count >= 25, DELETE FROM tablename
WHERE column_user = 'Alan'
ORDER BY column_date ASC
LIMIT ($count-24);
You must do the $count-24 calculation before you create the SQL
statement, because LIMIT accepts only an integer, not an expression.
4. INSERT INTO tablename <one new row for user 'Alan'>;
5. COMMIT;
Regards,
Bill K.
Bill Karwin Guest
-
Philipp Tölke #3
Re: How do I keep a fixed list of rows in a table?
Alan Williamson <alan@blog-city.com> schrieb:
In mySQL 5 it might be possible to create an update trigger, which> I want there ever to be only 25 rows stored for a given user; so when I
> INSERT a new item, I would need to remove/trim the items. Its this
> removing of the other items that is causing me a bit grief, as I can't
> seem to do it without doing another SELECT.
deletes old rows.
Cheers,
--
Philipp Tölke
PGP: 0x96A1FE7A
Philipp Tölke Guest



Reply With Quote

