萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> oracle教程 >> Oracle minus使用

Oracle minus使用

   新建兩個表:

  create table guotest1

  (

  sName varchar2(10),

  Gender varchar2(10)

  )

  create table guotest2

  (

  sName varchar2(10),

  Gender varchar2(10)

  )

  插入數據:

  insert into guotest1 values('a', 'm');

  insert into guotest1 values('b', 'm');

  insert into guotest1 values('c', 'f');

  insert into guotest1 values('d', 'f');

  insert into guotest2 values('e', 'm');

  insert into guotest2 values('f', 'm');

  insert into guotest2 values('g', 'f');

  insert into guotest2 values('h', 'f');

  1 minus返回的是兩個查詢結果表的差集

  例如:select * from guotest1 where rownum <= 4 minus select * from guotest1 where rownum <= 2

  返回結果:

  "SNAME","GENDER"

  "c","f"

  "d","f"

  2 minus返回的記錄總是來自於左邊的表

  例如:select * from guotest1 minus select * from guotest2

  返回結果:

  "SNAME","GENDER"

  "a","m"

  "b","m"

  "c","f"

  "d","f"

  像是說:如果左邊的表中的某個記錄存在於右邊的表中,則該記錄不會返回

copyright © 萬盛學電腦網 all rights reserved