title: select distinct join on multiple column on presto
body: <p>I have two tables in presto. </p>
  
  <p>So the table1 looks like:</p>
  
  <pre><code>+--------+-------------+--------
  |id1 | id2 |  date     | degree |
  +--------+-------------+--------
  |  1 |  10 |  20200101 |   1    |
  |  1 |  11 |  20200101 |   1    |
  |  1 |  11 |  20200101 |   1    |
  |  2 |  52 |  20200101 |   2 .  |
  |  2 |  52 |  20200101 |   2 .  |
  |  2 |  53 |  20200101 | . 2 .  |
  |  3 |  21 |  20200101 |   2 .  |
  | ...| ... |  ...      |  ...   |
  +--------+-----------+----------
  </code></pre>
  
  <p>and table2 is:</p>
  
  <pre><code> +--------+------------+-------+-------
  |id1 | id2 |  date     | price | rank |
  +--------+-------------+-------+-------
  |  1 |  10 |  20200101 |  1200 | 1    |
  |  1 |  10 |  20200101 |  1200 | 2    |
  |  1 |  10 |  20200101 |       |      |
  |  1 |  10 |  20200101 |  1300 | 1    |
  |  1 |  10 |  20200101 |  1300 | 2    |
  | ...| ... |  ...      |   ... |...   |
  +--------+-----------+-----------------
  </code></pre>
  
  <p>what I want to do to get price column from table2 and add it to table1 based three columns id1, id2 and date. If I do a simple join like this </p>
  
  <pre><code>select tab1.id1, tab1.id2, tab1.date, tab2.price
  from tab1
  left join tab2
  on tab1.id1 = tab2.id1
  and tab1.id2 = tab2.id2
  and tab1.date = tab2.date
  </code></pre>
  
  <p>this is what we have:</p>
  
  <pre><code> +--------+------------+----------------
  |id1 | id2 |  date     | price | degree |
  +--------+-------------+----------------
  |  1 |  10 |  20200101 |  1200 |   1    |
  |  1 |  10 |  20200101 |  1200 |   1    |
  |  1 |  10 |  20200101 |       |   1    |
  |  1 |  10 |  20200101 |  1300 |   1    |
  |  1 |  10 |  20200101 |  1300 |   1    |
  +--------+-----------+-------------------
  </code></pre>
  
  <p>but in fact what I want is this one:</p>
  
  <pre><code> +--------+------------+----------------
  |id1 | id2 |  date     | price | degree |
  +--------+-------------+----------------
  |  1 |  10 |  20200101 |  1200 | . 1 .  |
  |  1 |  10 |  20200101 |  1300 |   1 .  |
  +--------+-----------+-------------------
  </code></pre>