Jump to content

Newbie with Mysql problem


bbeamish

Recommended Posts

Hi there,

I hope you can help with this little problem of mine.

 

I have a table with data. when I INSERT data mysql places the row at the end of the table. Does anyone know how I can tell mysql to put the row at the beginning of the table and move all the old rows down one spot???

thanks

brian

 

p.s. I hope the following can tell you all the information about the platform I am working on:

MySQL 4.1.11-Debian_4sarge5-log running on mysql1.100ws.com as bribea5_dataset@ws2.100ws.com

Link to comment
Share on other sites

thanks for the prompt replies.

I understand your response but for the program I'm running I would ideally like to be able to add a row to the beginning of the table and not at the end.

 

More specifically, I am running a database of stock data. The data is stored from oldest to newest and for that reason if the row is added using "INSERT", today's data will be added to the beginning of the list (ie out of chronological order). It would make my life a lot easier if I could use an alternate command that entered the row at the beginning of the table and not at the end.

 

Right now I am considering pulling the existing data from the database, altering the order of the data in an array, splicing today's data into the array and finally writing the whole array back into the database (almost as a whole new dataset). That is very time consuming and tough on the server, so as I stated before, it would make my life a lot easier if there was a simple command that inserted the new row at the beginning of the table as apposed to the end.

thanks again....this will be my last attempt to get help here....

Brian

Link to comment
Share on other sites

Databases don't work the way you are suggesting. If they did, first of all they would start out slower then necessary and as the number of rows increased they would get slower and slower.

 

When you retrieve data you specific an ORDER BY clause in the query that will give you the data in either ascending or descending order using your existing DATE column.

 

There is no need to do all the manipulation, let the database engine retrieve the data the way you want by just writing the proper query statement.

Link to comment
Share on other sites

More specifically, I am running a database of stock data. The data is stored from oldest to newest and for that reason if the row is added using "INSERT", today's data will be added to the beginning of the list (ie out of chronological order). It would make my life a lot easier if I could use an alternate command that entered the row at the beginning of the table and not at the end.

Then you should have a field called "date_added", store NOW() in their when you run the insert, and then order by date_added ASC when you issue your queries.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.