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
*/
(
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
*/
解决方案 »
- 关于TINYINT(5)
- mysql + php 多列排序
- 如何进行分段排序?
- MySql-Front 为什么按装在win2000上后显示乱码?
- 在线,十万万火急,明天合同到期,mySQl中一时间段查询的问题,请高手指教
- 请教在使用load data infile语句时的问题
- 建表错误:MySQL said: You have an error in your SQL syntax near '( agegrp smallint(5) DEFAULT '0' NOT NULL, sex char(20) DEFAULT
- 这是mysql的漏洞吗?
- mysql高效子查询
- [新人求助]MySQL Error:Error on delete of
- 哪里可以下载mysql的源代码,请把详细地址贴出来?
- 如何获取数据库表中时间字段的值
只是我举得例子,真正的值没有规律,不知道该如何用变量替换,也可能我太菜,没想到替换方法。
因为其中一张表是ACCESS通过odbc导入到PhpMyAdmin里的,所以没有主键update b,(select uid from a) set b.nid=a.uid where b.nid=0;
我自己想的这语句没有成功,效果如下
/*
1
1
1
1
1
*/
只是update了第一个值,能改进吗?
增加自增字段两表,再替换
update b,uid a set b.nid=a.uid where a.id=b.id and b.nid=0;
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;
(
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;