1

Currently, by using the following, it is inserted after the last row.

INSERT INTO `table` (`text1`,`text2`,`text3`) VALUES('a', 'b', 'c')
Dharman
  • 30,962
  • 25
  • 85
  • 135
aandroidtest
  • 1,493
  • 8
  • 41
  • 68
  • 6
    And *why* would you want to do that? – lc. Jan 30 '13 at 09:19
  • 4
    It shouldn't `matter` where it is inserted, as you can sort your query when reading them back out to pretty much any order you like. – Gavin Jan 30 '13 at 09:20
  • @Ic So that when I display the table it will be in order. The contents are time dependent. – aandroidtest Jan 30 '13 at 09:20
  • 2
    Then learn some SQL and change the order when you fetch the data... – N.B. Jan 30 '13 at 09:21
  • @Gavin Because each time I can only get x number of information and once inserted into the table it is from the latest to earliest. When the next batch comes it is the most recent but gets inserted at the bottom. – aandroidtest Jan 30 '13 at 09:22
  • add a primary key, which is used by MySQL to order a table when `SELECT`ing data w/o given `ORDER` clause – rabudde Jan 30 '13 at 09:23
  • @aandroidtest - As previously suggested, you can simply sort the results by inserted date appearing first, meaning your latest result would appear at the top. – Gavin Jan 30 '13 at 09:24
  • 1
    @aandroidtest If you are relying on the implementation of MySQL to give you rows in some particular order based on their physical storage on disk, that is a recipe for trouble. There is absolutely no guarantee. – lc. Jan 30 '13 at 09:26
  • you can use Order By clause with ASC or DESC to display your records, if you want to display your custom random order you need to define an other new column in the DB table for sort, and set its value to 1 , 3, 5, 2 and then you can Oder By Sort(new column Name) Asc –  Jan 30 '13 at 09:26

1 Answers1

12

Rows in tables don't have an inherent order. The order is only specified by how you query it. If you don't specifiy how to order it, the database engine will just return the rows in a way that is most efficient depending on the layout of your table.

Your question can therefore not be answered, because there is no top and bottom in a database table. There is just data.

Also see this very very similar question and its answer

What you want to do is maybe specify a new column named ordering and write your ordering information there and then query the table using

SELECT * FROM `myTable` ORDER BY `ordering`
Community
  • 1
  • 1
F.P
  • 17,421
  • 34
  • 123
  • 189
  • Thanks understood, I have a field that is time. So when I display the table how could I display it by sorting based on this field? – aandroidtest Jan 30 '13 at 09:28
  • *sidenote*: the `ordering` column is suggested to be a `DATETIME`, in order to have easy sorting. – Raptor Jan 30 '13 at 09:29
  • @aandroidtest , @Florian has answered you already. just replace `ordering` by the time column name. – Raptor Jan 30 '13 at 09:30
  • 1
    @aandroidtest Just `ORDER BY` that field in `DESC` order. That way, the most recent dates will be at the top of your result set. – F.P Jan 30 '13 at 09:30