-- 33_exists_vs_in_cards.sql
-- Banking Pattern Pack — PostgreSQL
-- Purpose: EXISTS vs IN examples on cards.
-- Context: Retail bank example with customers, accounts, transactions, cards, loans.
-- Date: 2025-08-18
-- Notes:
--   * Safe to read; run on a development DB.
--   * Requires: CREATE privileges; some files may need superuser for extensions.
--   * Search path set to 'bank' schema for clarity.
SET search_path = bank, public;

-- EXISTS vs IN examples
-- EXISTS (correlated) tends to short‑circuit efficiently
SELECT EXISTS (
  SELECT 1 FROM bank.cards WHERE account_id = 1 AND active
);

-- IN works for small lists
SELECT account_id FROM bank.accounts WHERE account_id IN (SELECT account_id FROM bank.cards WHERE active);
