create table a
(
uid int(8)
)
insert into test (uid) select 1;
insert into test (uid) select 2;
insert into test (uid) select 3;
insert into test (uid) select 4;
insert into test (uid) select 5;后面还有,而且其中也有漏的,不是连续的值
/*
得到这样的效果:
uid
1
2
3
4
5
*/
再建张表b
create table b
(
nid int(8)
)
insert into test (nid) select 0;
insert into test (nid) select 0;
insert into test (nid) select 0;
insert into test (nid) select 0;
insert into test (nid) select 0;后面还有,而且其中也有漏的,不是连续的值
/*
得到这样的效果:
nid
0
0
0
0
0
*/
通过update,使表b达到以下效果
/*
nid
1
2
3
4
5
*/

解决方案 »

  1.   

    两表没有相同的KEY字段,直接用变量替换不行?
      

  2.   

    1,2,3,4,5
    只是我举得例子,真正的值没有规律,不知道该如何用变量替换,也可能我太菜,没想到替换方法。
    因为其中一张表是ACCESS通过odbc导入到PhpMyAdmin里的,所以没有主键update b,(select uid from a) set b.nid=a.uid where b.nid=0;
    我自己想的这语句没有成功,效果如下
    /*
    1
    1
    1
    1
    1
    */
    只是update了第一个值,能改进吗?
      

  3.   

    真实的值是什么,没有KEY字段,只有通过 游标循环来替换了
      

  4.   

    or
    增加自增字段两表,再替换
    update b,uid a set b.nid=a.uid where a.id=b.id and b.nid=0;
      

  5.   

    alter table a add column a1 int auto_increment primary key;
    alter table b add column b1 int auto_increment primary key;update a,b set b.nid=a.uid where a.a1=b.b1alter table q drop column a1;
    alter table b drop column b1;
      

  6.   

    看不懂你的例子。创建表A,结果往表TEST中插入记录。提供测试用例的时候,请1)尽可能使用你的原始代码, 2)自己先测试一下。  (否则在浪费大家时间的同时也浪费你自己的时间。)create table a
    (
    uid int(8)
    )
    insert into test (uid) select 1;
    insert into test (uid) select 2;
    insert into test (uid) select 3;
    insert into test (uid) select 4;
    insert into test (uid) select 5;