INSERT INTO然后多选

时间:2015-05-06 08:23:49

标签: mysql select insert

这可能吗?

INSERT INTO dfjw_favorite_list (`term_id`,`added_at`,`user_id`) SELECT 
trans.id , '1402309310' , '1' FROM dfjw_terms t,dfjw_language_groups g,
dfjw_terms trans WHERE t.id = '11800' AND g.language_group_id = 
t.language_group_id AND trans.language_group_id= g.id

之后我想从另一个表中选择,但我想在1 INSERT语句中执行此操作。像这样..但我怎么能把它结合起来呢?

SELECT id,'1402309310','1' FROM terms WHERE id = '11800';

最好的问候和提前感谢

1 个答案:

答案 0 :(得分:0)

您可以使用union all

INSERT INTO dfjw_favorite_list (`term_id`,`added_at`,`user_id`) 
SELECT 
trans.id , '1402309310' , '1' 
FROM dfjw_terms t,dfjw_language_groups g,
dfjw_terms trans 
WHERE 
t.id = '11800' 
AND g.language_group_id = t.language_group_id
AND trans.language_group_id= g.id
union all
SELECT id,'1402309310','1' FROM terms WHERE id = '11800';