Search notes:

Oracle SQL: MINUS

minus is a set operator.
create table tq84_minus_1 (
  val  number
);

create table tq84_minus_2 (
  val  number
);


insert into tq84_minus_1 values (1);
insert into tq84_minus_1 values (2);
insert into tq84_minus_1 values (2);
insert into tq84_minus_1 values (3);
insert into tq84_minus_1 values (3);
insert into tq84_minus_1 values (3);

insert into tq84_minus_2 values (2);


--   Note,
--     each distinct values is returned once only,
--     although inserted multiple times into tq84_minus_1
--    (especially the value 3).
--
select * from tq84_minus_1 minus
select * from tq84_minus_2;
--
--           VAL
--    ----------
--             1
--             3
--

drop table tq84_minus_1 purge;
drop table tq84_minus_2 purge;
Github repository Oracle-Patterns, path: /SQL/select/set_operators/minus_01.sql

Misc

The except keyword has the same semantics as the minus keyword.
Oracle 21c introduced minus all (and except all).

See also

The plan operation MINUS.
Using distinct in a view prevents the view from being updatable.
Set operators

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1740452935, '18.116.27.43', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/select/set-operators/minus/index(89): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78