title: Using neo4j DISTINCT and ORDER BY on different properties
body: <p>I am trying to run the following cypher query on neo4j version 1.9M02</p>
  
  <pre><code>START me=node(2)
              MATCH me-[:FOLLOWS]-&gt;friends
              ,friends-[fr:ADDED|STOCKS]-&gt;products
              ,me-[r?]-&gt;products
              WHERE r is null
              RETURN products._id
              ORDER BY fr.CreatedOn DESC
              SKIP 0
              LIMIT 10
  </code></pre>
  
  <p>I expect to get all products that are ADDED or STOCKED by my friends which are not ADDED or STOCKED by me, ordered by the relation creation time. This query returns correct results but has duplicate products._id values (One user ADDED the product and other user STOCKED it). But I need only one instance of this products._id so I tried</p>
  
  <pre><code>START me=node(2)
              MATCH me-[:FOLLOWS]-&gt;friends
              ,friends-[fr:ADDED|STOCKS]-&gt;products
              ,me-[r?]-&gt;products
              WHERE r is null
              RETURN DISTINCT products._id
              ORDER BY fr.CreatedOn DESC
              SKIP 0
              LIMIT 10
  </code></pre>
  
  <p>(Added the DISTINCT for products._id) But this time I got <strong><code>Unknown identifier fr</code></strong> error. So I added fr to RETURN statement</p>
  
  <pre><code>START me=node(2)
              MATCH me-[:FOLLOWS]-&gt;friends
              ,friends-[fr:ADDED|STOCKS]-&gt;products
              ,me-[r?]-&gt;products
              WHERE r is null
              RETURN DISTINCT products._id,fr
              ORDER BY fr.CreatedOn DESC
              SKIP 0
              LIMIT 10
  </code></pre>
  
  <p>This query works without any error but returns duplicate product ids as before.</p>
  
  <p>I've been only playing with neo4j for last couple of days, so not expert at all. I'd really appreciate if someone could help me out here.</p>