页:
[1]
| anyforever | 2008-5-15 05:46 AM |
|
请教个sql插入的问题
现有一问题,从另一表中取出某字段的值,然后插入到某一表中,但是插入语句还有其它的值。形如
并且是循环的取出不同的数据行中的数据
select name from table1 where id='$id[$i]';
insert into table2(col1, col2, name) values('$col1', '$col2', name);
values里面的name是上面select取出来的。怎么写成一条语句? |
|
insert into table2 select '$col1', '$col2', name from table1 where id='$id[$i]'
如果需要自增ID 加多一个字段值NULL
insert into table2 select NULL,'$col1', '$col2', name from table1 where id='$id[$i]' |
| anyforever | 2008-5-15 08:18 AM |
|
谢谢2楼朋友
不过貌似你误解我的意思了
我的是两个$的变量不是查出来的,这两个是post过来的。只有那个name是查出来的。 |
|
| 你没有测试,怎么知道不行?'$col1', '$col2',随便你什么值,只不过不管插入多少条记录,这两个值都是一样的而已。我是测试过才回复你,不会忽悠你。 |
Powered by Discuz! Archiver 6.1.0
© 2001-2006 Comsenz Inc.
Processed in 0.005988 second(s), 2 queries |