Oracle not exsits select 1
exsits内で使用する「select 1」は「select *」と内容的には同じ
■testテーブルとtest2テーブルを用意
・select * from test;
| id | name |
|---|---|
| 1 | tanaka |
| 2 | nakagawa |
| 3 | yoshida |
・select * from test2;
| id | age |
|---|---|
| 1 | 20 |
| 2 | 30 |
| 3 | 40 |
■select結果
・select * from test t1, test2 t2
where not exists (select 1 from test2 where t1.id = t2.id and t2.id = 2);
| id | name | id_1 | age |
|---|---|---|---|
| 1 | tanaka | 1 | 20 |
| 1 | tanaka | 2 | 30 | 1 | tanaka | 3 | 40 |
| 2 | nakagawa | 1 | 20 |
| 2 | nakagawa | 3 | 40 | 3 | yoshida | 1 | 20 | 3 | yoshida | 2 | 30 | 3 | yoshida | 3 | 40 |
・select count(1) from test t1, test2 t2
where not exists (select 1 from test2 where t1.id = t2.id and t2.id = 2);
| count(1) |
|---|
| 8 |