title: NHibernate How to Select distinct objects based on specific property using HQL?
body: <p>How can HQL be used to select specific objects that meet a certain criteria?</p>
  
  <p>We've tried the following to generate a list of top ten subscribed RSS feeds (where SubscriptionCount is a derived property):</p>
  
  <pre><code>var topTen = UoW.Session.CreateQuery( @"SELECT distinct rss 
                                                   FROM RssFeedSubscription rss
                                                   group by rss.FeedUrl
                                                   order by rss.SubscriptionCount DESC
                                                   ")
  .SetMaxResults(10)
  .List&lt;RssFeedSubscription&gt;();
  </code></pre>
  
  <p>Where the intention is only to select the two unique feed URLs in the database, rather than the ten rows int the database instantiated as objects. The result of the above is:</p>
  
  <pre><code>Column 'RssSubscriptions.Id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
  ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
  </code></pre>
  
  <p>It's possible just to thin out the results so that we take out the two unique feed URLs after we get the data back from the database, but there must be a way to do this at the DB level using HQL? </p>
  
  <p>EDIT: We realise it's possible to do a Scalar query and then manually pull out values, but is there not a way of simply specifying a match criteria for objects pulled back?</p>