English 中文(简体)
ql表格中的 revers变
原标题:reversing ids in sql table
  • 时间:2010-12-15 06:21:15
  •  标签:
  • php
  • sql
  • logic

i have a table with primary id
1 simer
2 pawan
3 deep
4 sheep
5 man
i want reverse this order
5 simer
4 pawan
3 deep
2 sheep
1 man

how can i do this with programming or sql? i dont want to use order by in sql

最佳回答

分别:

(1) 选择按 des令订购的所有行文,然后在ending令中插入新桌子,而且表格“AUTO_INCREMENT”将按相反顺序排列标识。 现在,你可以把这几行带回原来的表格,并附上新的标识。

(2) 将所有按停电命令开立的牢房选入一个方案,删除,并重新加入新的身份证:

$sql = "SELECT id, name FROM table ORDER BY id DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
    $rows[] = $row;
}

//empty the table, to avoid primary key conflicts
mysql_query("TRUNCATE TABLE table");    

$i = 1;
foreach ($rows as $row) {
  mysql_query("INSERT INTO table (id, name) VALUES ($i,  " . mysql_real_escape_string($row[ name ]) . ")");
  $i++;
}
问题回答

i 有意使用q

但这正是按条款提供书面证据的理由。

您是否只是想扭转目前数据顺序,还是想请您的系统将下降的序列号分配给新的记录?

前者将成为后者的前提条件......。

UPDATE yourtable SET id=(4294967295-id);

请注意,虽然你可以控制每个新增加的汽车价值与以前不同的数量(具体指明汽车增益-增减),但仅仅确定这到-1并不能解决问题,因为这一三角洲的基值从您处得到,因此即使我的舱单允许你具体说明一台汽车的增益,你最终会重复一行,因此,你需要用简单的电解手法,用一台轮式发电机代替自动加固。 然后,你们需要重新制定你们的所有法典,以使用序列生成器,而不是INSERT_ID()/ mysql_insert_id()。

是否更简单地说,只是使用英文。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签