title: Removing duplicate results while using UNION SELECT
body: <p>Ive got a problem with a MySQL query.</p>
  
  <p>Let's say, we have two tables:</p>
  
  <h2>id    qty</h2>
  
  <p>1......1</p>
  
  <p>2......1</p>
  
  <p>3......1</p>
  
  <p>4......3</p>
  
  <p>and</p>
  
  <h2>id    qty</h2>
  
  <p>1......2</p>
  
  <p>2......1</p>
  
  <p>6......1</p>
  
  <p>7......2</p>
  
  <p>What I actually need to get is a result filtered by id, so there are no duplicate id's. If they are two same id's, only id whith a higher qty number will be considered. So in and ideal situation I would get this result:</p>
  
  <h2>id    qty</h2>
  
  <p>1......2</p>
  
  <p>2......1</p>
  
  <p>3......1</p>
  
  <p>4......3</p>
  
  <p>6......1</p>
  
  <p>7......2</p>
  
  <p>What Ive tried so far is a UNION SELECT, which works fine, but when it comes across a duplicate ID it wont remove duplicates, as it removes just duplicates rows. GROUP BY didnt help either. I could still sort this out through an array in PHP, but I would love having this sorted at MySQL level if possible. </p>
  
  <p>Thanks everyone for you help, it's much appreciated!</p>