title: Union query distinct on one column
body: <p>I would like results from the second query to override results from the first query:</p>
  
  <pre><code>SELECT "panel_restaurants_restaurant"."id",
         "panel_restaurants_restaurant"."name",
         "panel_restaurants_restaurant"."logo",
         "panel_restaurants_restaurantfeatures"."currency" AS "currency",
         ST_DistanceSphere(location, ST_GeomFromText('POINT(0.0 0.0)',4326)) AS "distance",
         "panel_meals_meal"."id" AS "meal_id",
         "panel_meals_meal"."status" AS "meal_status",
         "panel_meals_meal"."available_count" AS "available_dishes",
         "panel_meals_meal"."discount_price" AS "discount_price",
         "panel_meals_meal"."normal_price" AS "normal_price",
         "panel_meals_meal"."collection_from" AS "pickup_from",
         "panel_meals_meal"."collection_to" AS "pickup_to",
         "panel_meals_meal"."description" AS "meal_description"
  FROM "panel_restaurants_restaurant"
  INNER JOIN "panel_restaurants_restaurantfeatures" ON (
      "panel_restaurants_restaurantfeatures"."restaurant_id" = "panel_restaurants_restaurant"."id")
  LEFT OUTER JOIN "panel_meals_meal" ON ("panel_restaurants_restaurant"."id" = "panel_meals_meal"."restaurant_id"
                  AND "panel_meals_meal"."status" = 0
                  AND (
                  ("panel_meals_meal"."collection_from" AT TIME ZONE 'Europe/Warsaw')::date = DATE 'today' OR
                  ("panel_meals_meal"."collection_from" AT TIME ZONE 'Europe/Warsaw')::date = DATE 'tomorrow'
                  )
                  AND "panel_meals_meal"."collection_to" &gt; '2017-07-29 19:33:47.992075+00:00'
                  AND "panel_meals_meal"."available_count" &gt; 0)
  WHERE "panel_restaurants_restaurant"."status" = 2
  UNION
  SELECT "panel_restaurants_restaurant"."id",
         "panel_restaurants_restaurant"."name",
         "panel_restaurants_restaurant"."logo",
         "panel_restaurants_restaurantfeatures"."currency" AS "currency",
         ST_DistanceSphere(location, ST_GeomFromText('POINT(0.0 0.0)',4326)) AS "distance",
         "panel_meals_meal"."id" AS "meal_id",
         "panel_meals_meal"."status" AS "meal_status",
         "panel_meals_meal"."initial_count" AS "available_dishes",
         "panel_meals_meal"."discount_price" AS "discount_price",
         "panel_meals_meal"."normal_price" AS "normal_price",
         "panel_meals_meal"."collection_from" AS "pickup_from",
         "panel_meals_meal"."collection_to" AS "pickup_to",
         "panel_meals_meal"."description" AS "meal_description"
  FROM "panel_restaurants_restaurant"
  INNER JOIN "panel_restaurants_restaurantfeatures" ON (
         "panel_restaurants_restaurantfeatures"."restaurant_id" = "panel_restaurants_restaurant"."id")
  LEFT OUTER JOIN "panel_meals_meal" ON (
      "panel_restaurants_restaurant"."id" = "panel_meals_meal"."restaurant_id" AND
      "panel_meals_meal"."status" = 0)
  INNER JOIN "panel_meals_mealrepeater" ON (
      "panel_meals_mealrepeater"."meal_id" = "panel_meals_meal"."id")
  WHERE "panel_restaurants_restaurant"."status" = 2    AND "panel_meals_mealrepeater"."saturday" = true
  ORDER BY distance ASC
  </code></pre>
  
  <p>For example - the first query may return nulls for what comes from the <code>panel_meals_meal</code> table, but the second one will return something - in that situation I will have the same values for <code>id</code>, <code>name</code>, <code>logo</code>, <code>currency</code>, <code>distance</code> and different values (nulls returned from the first query, and <code>something</code> from the other one) for all the other ones. </p>
  
  <p>So the question is - how do I make this <code>UNION</code> distinct on a certain range of columns (actually only one would suffice - <code>id</code>)?</p>