插入2选择sql结果到一个插入sql中

时间:2013-04-12 17:28:44

标签: sql postgresql

我有一张包含2个字段的表格。如何从2 sql结果的结果中插入这2个字段。

 insert into access (user,page)
(select id as user from users where id =5,
select pagename as page from pages where id =10)

2个表之间没有关系。我不认为我可以加入。

2 个答案:

答案 0 :(得分:1)

insert into access ("user", page) values
(  (select id as user from users where id =5),
   (select pagename as page from pages where id =10)
)

答案 1 :(得分:1)

insert into access (user,page)
select users.id as user, 
       pages.pagename as page 
from users,pages
where users.id = 5
  and pages.id = 10