title: SQLITE - Delete rows with self join?
body: <p>I am trying to delete all rows in a simple table that have a duplicate value except for the duplicate with the highest id.</p>
  
  <p>Table: </p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS [Expression] (
                        [ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                        [Value] VARCHAR(2048) NOT NULL
                        )
  </code></pre>
  
  <p>Attempted Queries:</p>
  
  <pre><code>DELETE Expression 
  WHERE EXISTS (
      SELECT 1 
      FROM Expression Exp2 
      WHERE Expression.Value=Exp2.Value 
          AND Expression.Id &lt; Exp2.Id)
  </code></pre>
  
  <p>fails with </p>
  
  <blockquote>
    <p>"SQL logic error or missing database near "Expression":syntax error"</p>
  </blockquote>
  
  <pre><code>DELETE Exp1 
  FROM Expression Exp1 
    INNER JOIN Expression Exp2 
      ON Exp1.Value=Exp2.Value AND Exp1.Id &lt; Exp2.Id
  </code></pre>
  
  <p>fails with </p>
  
  <blockquote>
    <p>"SQL logic error or missing database near "Exp1":syntax error"</p>
  </blockquote>
  
  <p>What syntax do I need to use?</p>