title: How to copy SQL table data without duplicates?
body: <p>I have a table called <strong>MovementEntry</strong></p>
  <p>Sample Data:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>Quantity</th>
  <th>Price</th>
  <th>EntrySort</th>
  <th>Product</th>
  <th>Movement</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>80</td>
  <td>8$</td>
  <td>Light</td>
  <td>Beer</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>70</td>
  <td>9$</td>
  <td>Dark</td>
  <td>Lager</td>
  <td>1</td>
  </tr>
  <tr>
  <td>3</td>
  <td>40</td>
  <td>10$</td>
  <td>Dark</td>
  <td>Ale</td>
  <td>2</td>
  </tr>
  <tr>
  <td>4</td>
  <td>55</td>
  <td>7$</td>
  <td>Red</td>
  <td>Vine</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Sample Output after running the query (below):</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>Quantity</th>
  <th>Price</th>
  <th>EntrySort</th>
  <th>Product</th>
  <th>Movement</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>80</td>
  <td>8$</td>
  <td>Light</td>
  <td>Beer</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>70</td>
  <td>9$</td>
  <td>Dark</td>
  <td>Lager</td>
  <td>1</td>
  </tr>
  <tr>
  <td>3</td>
  <td>40</td>
  <td>10$</td>
  <td>Dark</td>
  <td>Ale</td>
  <td>2</td>
  </tr>
  <tr>
  <td>4</td>
  <td>55</td>
  <td>7$</td>
  <td>Red</td>
  <td>Vine</td>
  <td>2</td>
  </tr>
  <tr>
  <td>5</td>
  <td>80</td>
  <td>8$</td>
  <td>Light</td>
  <td>Beer</td>
  <td>2</td>
  </tr>
  <tr>
  <td>6</td>
  <td>70</td>
  <td>9$</td>
  <td>Dark</td>
  <td>Lager</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>When I run it a second time it shouldn't do anything since all the <strong>Products</strong> are already in the table.</p>
  <p>This is the query that is supposed to copy all the rows with <em>minimum</em> <strong>Movement</strong> value into the same table but with the <em>maximum</em> <strong>Movement</strong> value only without duplicate <strong>Product</strong>s.</p>
  <pre><code>INSERT INTO MovementEntry (Quantity, Price, EntrySort, Product, Movement)
  (SELECT Quantity, Price, EntrySort, Product, (SELECT MAX(IncOutc) FROM Movement) 
  FROM MovementEntry 
  WHERE Movement = (SELECT MIN(IncOutc) FROM Movement))
  AND NOT EXISTS(SELECT Product FROM MovementEntry)
  </code></pre>
  <p>But it gives me an error:</p>
  <blockquote>
  <p>Incorrect syntax near the keyword 'AND'.</p>
  </blockquote>
  <p>On line 5.</p>
  <p><strong>UPDATE</strong></p>
  <p><strong>Movement</strong> Table Structure (as requested)</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>Added At</th>
  <th>IncomeOutcome</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>2021-07-02</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>2021-09-02</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>(Here in the <strong>IncomeOutcome</strong> filed 1 means that Products were received and 2 means that they were sold)</p>