0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

20250905_AP_相関副問い合わせ

0
Posted at

相関副問い合わせとは

副問い合わせの一種で、外側のクエリ(メインクエリ)の行に依存して繰り返し評価される副問い合わせのこと。
普通の副問い合わせは一度だけ実行されて結果が返りますが、相関副問い合わせは外側のテーブルの各行ごとに実行される。
行ごとの比較、条件付き除外、存在確認などの用途で使用される。

相関副問い合わせと判断できる要素

副問い合わせの中で外側のクエリのカラムを参照している。
外側の行ごとに副問い合わせが評価される。

SELECT e.employee_id, e.name, e.salary, e.department_id
FROM employees e
WHERE e.salary > (
SELECT AVG(e2.salary)
FROM employees e2
WHERE e2.department_id = e.department_id
);

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?