首先我们在goods表中查询
SELECT goods_id FROM ecs_goods
WHERE goods_name
= '23423423' LIMIT 1
查询goods_name对应的goods_id的值
然后把查询到的goods_id的值作为参数,
INSERT INTO ecs_comment
(comment_id
, comment_type
, id_value
, email
, user_name
, content
, comment_rank
, add_time
, ip_address
, status
, parent_id
, user_id
) VALUES (NULL, '0', 'goods_id', 'asdas', 'asdas', '23324324', '0', '2015-04-05 19:55:05', '', '1', '0', '0');
插入到另一个表中的新记录里
插入语句中的goods_id的值就是上面查询语句中的goods_id的值
如果可以的话用UNION;
直接将查询结果合并到另一个表里;
这个应该适合多条记录;
也许有更好的办法,你可以从网上下载一本mysql的书看看有没有这样更好的例子;
如果回答对你有帮助,请采纳
像下面这样
create table test_table(
f1 varchar(20),
f2 varchar(10)
);
create table test_table2(
k1 varchar(20),
k2 varchar(20)
);
insert into test_table2(k1,k2) values('2323','abadc');
insert into test_table(f1,f2)
select '1',(select k1 from test_table2 where k2='abadc' LIMIT 1);