如果不存在,则插入从先前查询中获取的行的 table 值
Insert into table value for rows fetched from previous query if not exists
我有 2 个表,比方说 'ACCESSENTRY'
和 PROJECT
,并且 PROJECT
包含列 ROLE、ACCESSENTRY。我需要找到 ACCESSENTRY 等于 'A' 的第一行,并为这些行插入 ACCESSENTRY
带有获取的 'ROLE[= 的新行21=]' 并给定 ACCESSENTRY,但如果此行不存在。
所以让我们在这个查询中说:
我想你想要 not exists
:
insert into ROLEE (role, accessentry)
select r.role, 'ACCESS'
from ROLEE r
where r.ACCESSENTRY = 'A' and
not exists (select 1 from rolee r2 where r2.role = r.role and r2.column2 = 'ACCESS');
您可以将 INSERT ... SELECT
与 NOT EXISTS
一起使用:
insert into UM_ACCESSENTRY(role, accessentry)
select p.role, 'test'
from UM_PROJECT p
where p.PROJECT='ProjectName'
and not exists (
select 1 from UM_ACCESSENTRY a
where a.role = p.role and a.accessentry = 'test'
)
我有 2 个表,比方说 'ACCESSENTRY'
和 PROJECT
,并且 PROJECT
包含列 ROLE、ACCESSENTRY。我需要找到 ACCESSENTRY 等于 'A' 的第一行,并为这些行插入 ACCESSENTRY
带有获取的 'ROLE[= 的新行21=]' 并给定 ACCESSENTRY,但如果此行不存在。
所以让我们在这个查询中说:
我想你想要 not exists
:
insert into ROLEE (role, accessentry)
select r.role, 'ACCESS'
from ROLEE r
where r.ACCESSENTRY = 'A' and
not exists (select 1 from rolee r2 where r2.role = r.role and r2.column2 = 'ACCESS');
您可以将 INSERT ... SELECT
与 NOT EXISTS
一起使用:
insert into UM_ACCESSENTRY(role, accessentry)
select p.role, 'test'
from UM_PROJECT p
where p.PROJECT='ProjectName'
and not exists (
select 1 from UM_ACCESSENTRY a
where a.role = p.role and a.accessentry = 'test'
)