title: PostgreSQL: delete rows returned by subquery
body: <p>The basic syntax for <code>DELETE</code> is</p>
  
  <pre><code>DELETE FROM table
  WHERE condition
  </code></pre>
  
  <p>Is there a straightforward way to use subquery/alias in a <code>DELETE</code> statement, something like below?</p>
  
  <pre><code>DELETE FROM (subquery) as sub
  WHERE condition
  </code></pre>
  
  <p>Below is a minimal working table and my failed attempt to use subquery/alias:</p>
  
  <pre><code>---create table
  create table orderT (
      id integer PRIMARY KEY,
      country_code   varchar(2),
      created_date date,
      closed_date date);
  
  ---populate table
  INSERT INTO orderT VALUES (1, 'US', now(), now() + interval '1 day' * 21);
  INSERT INTO orderT VALUES (2, 'CA', now(), now() + interval '1 day' * 35);
  
  --This does not work    
      DELETE
      FROM
        (SELECT *
         FROM orderT) AS sub
      WHERE sub.id = 1;
  </code></pre>
  
  <p>You can try the code <a href="http://rextester.com/YUZRVC76914" rel="nofollow noreferrer">here</a>. </p>
  
  <p><strong>PostgreSQL 9.5</strong></p>