title: sum columns without duplicates in Laravel
body: <p>I have these 3 tables: tables, reservation and table_reservation. The last one is the pivot, the thing is that I want to sum the amount of each reservation according to the given date, but without duplicates, that is, there is a reservation with 3 tables taken, these 3 records are added in the pivot table and sum 3 times the amount of a reservation, what I do not want.</p>
  
  <p>I leave the tables and my code.</p>
  
  <p><code>table_reservation</code></p>
  
  <pre><code>| date       | table_id | reservation_id |
  | 2019-06-12 | 2        | 1              |
  | 2019-06-12 | 3        | 1              |
  | 2019-06-12 | 4        | 1              |
  | 2019-06-12 | 1        | 2              |
  </code></pre>
  
  <p><code>reservation</code></p>
  
  <pre><code>| id | name        | emp_id | amount | other    |
  | 1  | Luis Miguel | 2      | 200    | vdvvdvdv |
  | 2  | carloz      | 2      | 234    | dwdq     |
  </code></pre>
  
  <p><code>tables</code></p>
  
  <pre><code>| id | name |
  | 1  | A1   |
  | 2  | B2   |
  | 3  | A2   |
  | 4  | A4   |
  | 6  | B4   |
  </code></pre>
  
  <p>PHP code</p>
  
  <pre><code>    DB::table('reservation')
      -&gt;join('table_reservation', 'reservation.id', '=', 'table_reservation.reservation_id')
      -&gt;join('tables', 'table_reservation.mesa_id', '=', 'tables.id')
      -&gt;join('empleados', 'reservation.emp_id', '=', 'emp.id')
      -&gt;select('reservation.id',DB::raw('group_concat(tables.name) as y'),'reservation.name', 'emp.name as x','reservation.amount','reservation.other', 'table_reservation.date', DB::raw("SUM(reservation.amount) as count"))
      -&gt;select(DB::raw("SUM(reservation.amount) as count"))
      -&gt;distinct()
      -&gt;groupBy('reservation.id')
      -&gt;where('table_reservation.date',$date)-&gt;get();
  </code></pre>
  
  <p>I get the following:</p>
  
  <pre><code>[{"count":"600"},{"count":"234"}]
  </code></pre>
  
  <p>It should be 200 instead of 600</p>