Home >Database >Mysql Tutorial >mysql 如何把查询到的结果插入到另一个表中

mysql 如何把查询到的结果插入到另一个表中

WBOY
WBOYOriginal
2016-06-06 09:41:442401browse

mysql查询插入新表

首先我们在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的值

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn