View Full Version : Adding at the start of a table
gyrbo
June 8th, 2001, 14:57
I there any way to add a line at the start of a MySQL table?
atlas
June 8th, 2001, 17:31
Originally posted by gyrbo
I there any way to add a line at the start of a MySQL table?
I don't understand exactly what you want to do. Perhaps be a bit more specific...
-mk
gyrbo
June 9th, 2001, 05:01
Well, I have a table in a MySQL db. I want to get the last 6 entry's that are added to that table. So you just take the first 6, and add new ones at the start. ex:
id|val1|val2
-------------------------------
0|test|test2
1|test line2|test2 line2
Now I want to add a line so:
id|val1|val2
-------------------------------
0|added|line
1|test|test2
2|test line2|test2 line2
Does it make sence now?
Woofcat
June 9th, 2001, 15:20
No efficient way... You'd have to 'update whatever set id=id+1' and then 'insert into whatever values("0","added","line")'
atlas
June 9th, 2001, 16:02
Woofcat is right, there isn't an efficient way of doing that.
Your best bet would probably be to retrieve your records in reverse
order by id desc
Or do 2 select statements -- one to find the largest ID, and one to get your ID. Then do some subtraction :)
-mk
gyrbo
June 9th, 2001, 16:20
I just knew this was going to be hard. Well, I'll use newspro or something then.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.