bbeamish Posted December 5, 2007 Share Posted December 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/80209-newbie-with-mysql-problem/ Share on other sites More sharing options...
teng84 Posted December 5, 2007 Share Posted December 5, 2007 i dont think thats necessary because you can list all your file just the way you want using orderby clause Quote Link to comment https://forums.phpfreaks.com/topic/80209-newbie-with-mysql-problem/#findComment-406589 Share on other sites More sharing options...
fenway Posted December 5, 2007 Share Posted December 5, 2007 There's no "beginning" or "end"... records are simply in a mathematical set, a grouping of sorts. Ask for your data sorted however you'd like. Why do you care how mysql stores the data internally? Quote Link to comment https://forums.phpfreaks.com/topic/80209-newbie-with-mysql-problem/#findComment-406601 Share on other sites More sharing options...
bbeamish Posted December 5, 2007 Author Share Posted December 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/80209-newbie-with-mysql-problem/#findComment-406633 Share on other sites More sharing options...
PFMaBiSmAd Posted December 5, 2007 Share Posted December 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/80209-newbie-with-mysql-problem/#findComment-406634 Share on other sites More sharing options...
fenway Posted December 5, 2007 Share Posted December 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/80209-newbie-with-mysql-problem/#findComment-406914 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.