-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Count zero in left join query
PostPosted: Tue Nov 21, 2006 10:00 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
Hi

I have two classes: Customer and Survey. Customer has many-to-one relation to Survey, and Survey has one-to-many (ISet) relation to Customer.

Survey has an integer field theYear, Customer has a string field Name.

I need a following result with one query: Customer.Name, Count(Customer.Surveys) for a particular theYear value.

The following query
Code:
select c.Name,count(*) from Customer left join c.Surveys s where s.theYear=2005 or s.theYear is null

gives me partial result - customers with some surveys in a year (and the number of surveys in that year) and customers with no surveys at all (number=0). There are no customers only with surveys with theYear<>2005.

I know where is the problem ( simmilar SQL query gives the exact result ), but I have no idea how to modify the query to get full list of customers. In SQL i would do sth like this:
Code:
select c.Name,(select count(*) from Survey s where s.CustomerId=c.Id and s.theYear=2005) from Customer c

but it is not possible in HQL. Can anybody help?

_________________
michal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.