NHibernate HQL - select count(*) with having - can't get it to work -


trying run following hql nhibernate:

select count(distinct t) tweetcount tweet t     join t.tweeter u     left join t.votes v     left join t.tags tag t.app = :app having count(distinct v) > 0 

but reason having clause being ignored , it's counting tweets when 2 tweets have vote. want count number of tweets have @ least 1 vote.

here databasemy twitter database

i tried adding group query so:

select count(distinct t) tweetcount tweet t     join t.tweeter u     left join t.votes v     left join t.tags tag t.app = :app group t having count(distinct v) > 0 

...but ended returning collection containing 2 integers each set '1' instead of unique result.

this fit thwe bill

select count(distinct t.id) tweetcount tweet t     inner join t.votes v t.app = :app 

since inner joining votes table, tweet has no votes not counted against result set.

an other way using pure hql syntax be

select count(distinct t.id) tweetcount tweet t t.app = :app , size(t.votes) > 0 

which create sql statement depending on dialect, size() function hql-specific collections, see 13.8 nhibernate reference


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -