表结构和数据如下:(SQL Server 2005) ID都是数据库自动生成的32位UUID
tb1
ID Name1 Name2
newid() 1 abctb2
ID Name1 Name2
newid() 2 cbatb3
ID tb1id tb2idinsert into tb3(newid(),select recordid from tb1 where Name1=1,select recordid from tb2 where Name1=2);请问这样的insert 语句该怎么写???
tb1
ID Name1 Name2
newid() 1 abctb2
ID Name1 Name2
newid() 2 cbatb3
ID tb1id tb2idinsert into tb3(newid(),select recordid from tb1 where Name1=1,select recordid from tb2 where Name1=2);请问这样的insert 语句该怎么写???
select newid name1,name2 from tb1 where name1=1
union all
select newid name1,name2 from tb2 where name1=2
SELECT NEWID(), t1.ID, t2.ID
FROM
(SELECT ID FROM tb1 where Name1=1) t1,
(SELECT ID FROM tb2 where Name1=2) t2,
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.
insert tb3
select newid(), a.name1,b.name2 from tb1 a,tb2 b where a.name1=1 and b.name1=2