insert a row
#1

I was wondering if it is actually possible to insert a row on top of the table, using MySQL.
PHP код:
INSERT INTO 
inserts a row at the bottom of the table, though I was wondering if it is possible to add a row on top of the table.
Reply
#2

****** my friend, use ******,
check this link, it has some interesting tips
Reply
#3

I see, I'm still confused on how the query should look like, an example would be appreciated.
Reply
#4

Of course it's possible. When auto increment is enabled (which should always be) on a table, rows are ordered by their SQL ID (the ID given by auto increment).

I'm not sure why you want to do this, unless it's for organization/grouping purposes. However, follow these guidelines:
  1. UPDATE all existing row IDs by 1 ** `sql_id` + 1 **
  2. INSERT the new row INTO the table, setting the SQL ID to 1
  3. Increase the table's auto increment value by 1
Reply
#5

Makes sense, thanks.
Reply
#6

The "top" of the table is relative because it is determined by the way the results are ordered. A surrogate primary key should never be altered once set.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)