重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

【GOLF me!】初月無料お試し

IN は何れかの行が比較演算子の結果と一致したら(真になったら)その結果を返して処理を打ち切る
any ?
ALL は一致しても処理を打ち切らず全てを比較して結果を返す

anyはどんな動きをしているのでしょうか?

A 回答 (1件)

in/any/allの関係は以下の通り



create table tbl_a(id int primary key,name varchar(10),index(Name));
insert into tbl_a values(1,'A'),(2,'B'),(3,'C'),(4,'D'),(5,'E');
create table tbl_b(id int primary key,name varchar(10),index(Name));
insert into tbl_b values(2,'x'),(4,'y'),(6,'z');

select * from tbl_a
where id= ANY (select id from tbl_b);

select * from tbl_a
where id IN (select id from tbl_b);

select * from tbl_a
where not id<> ALL (select id from tbl_b);

これをexistsで処理するとこう

select * from tbl_a as t1
where exists (select 1 from tbl_b where id=t1.id);
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

関連するカテゴリからQ&Aを探す