简体   繁体   中英

minus a set of some constant values from a set of values of a column in oracle

there is a table like id- name-roll i have some set of constant given value of roll like- (1,2,6,8,5) let it be set A table has roll like(1,2,3,4,5,6,7) let it be set B i want to know AB means those values of roll which is not in the table but exist in the given constant set A

i tried select roll from "tablename" where roll not in(1,2,6,8,5); but it return just opposite- it return BA but i want AB please help i also tried

select (1,2,6,8,5) from dual minus select roll from tablename; but it gives some syntex error

Is this what you want?

select a.*
from (select 1 as id from dual union all
      select 2 as id from dual union all
      select 6 as id from dual union all
      select 8 as id from dual union all
      select 5 as id from dual
     ) a
where not exists (select 1 from b where a.id = b.id);
(select 1 as id from dual
         union all
select 2 from dual
         union all
select 6 from dual
         union all
select 8 from dual
         union all
select 5 from dual
         )
minus
Select id from b

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM