title: PostgreSQL: Inner join on a specific value
body: <ol>
  <li><p>Is it better (mainly performance-wise) to do:</p>
  
  <pre><code>SELECT u.email, s.id
  FROM users s, sessions s
  WHERE u.id = s.user_id
  AND u.id = 1
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>SELECT u.email, s.id
  FROM users s, sessions s
  WHERE u.id = 1
  AND s.user_id = 1
  </code></pre></li>
  <li><p>What about:</p>
  
  <pre><code>DELETE FROM users u
  USING sessions s
  WHERE u.id = s.user_id
  AND u.id = 1
  AND s.id = 2
  RETURNING TRUE;
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>DELETE FROM users u
  USING sessions s
  WHERE u.id = 1
  AND s.user_id = 1
  AND s.id = 2
  RETURNING TRUE;
  </code></pre></li>
  </ol>
  
  <p>Table Schema:</p>
  
  <pre><code>CREATE EXTENSION "uuid-ossp";
  
  CREATE TABLE users (
      id bigserial PRIMARY KEY,
      email varchar(254) NOT NULL,
      created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
  );
  CREATE UNIQUE INDEX on users (lower(email));
  
  CREATE TABLE sessions (
      user_id bigint PRIMARY KEY REFERENCES users ON DELETE CASCADE,
      id uuid NOT NULL DEFAULT uuid_generate_v4(),
      created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
  );
  </code></pre>