トップ 差分 一覧 ping ソース 検索 ヘルプ PDF RSS ログイン

SQL 複数行に対して、AND条件を指定



目次



記事一覧

キーワード

SQL 複数行に対して、AND条件を指定


複数行に対して、AND条件を指定する。
列f2に'A' AND 'B' を含む列f1のグループを抽出

create table test01 (
    f1 varchar2(2),
    f2 varchar2(2),
    f3 varchar2(2)
)
/

insert into test01 values('01','A','a');
insert into test01 values('01','B','b');
insert into test01 values('01','C','c');
insert into test01 values('02','A','a');
insert into test01 values('02','B','b');
insert into test01 values('03','A','a');
/

select * from test01
where f1 in (
  select t1.f1 from 
    (select distinct(f1) from test01
     where f2 = 'A') t1,
    (select distinct(f1) from test01
     where f2 = 'B') t2
  where
    t1.f1 = t2.f1
)
/

F1   F2   F3
---- ---- ----
01   A    a
01   B    b
01   C    c
02   A    a
02   B    b



YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto

Copyright© 矢木 浩人 All Rights Reserved.