-->
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.  [ 2 posts ] 
Author Message
 Post subject: left outer joins and where clause
PostPosted: Thu Dec 18, 2003 8:27 am 
Newbie

Joined: Wed Oct 01, 2003 8:56 am
Posts: 6
Hi

I hope somebody can help me or point me in the right direction.

I have the following query

String findString = "select prov.province, " +
" count(con) " +
" from Province prov left outer join prov.addresss adr " +
" left outer join adr.consumerBrand conb " +
" left outer join conb.consumer con " +
" group by prov.province" +
"";


Which returns the following data:

WC : 0
Western Cape : 1

What I need to do now is limit the count of Consumer con using brandName. So if I run the following query

String findString = "select prov.province, " +
" count(con) " +
" from Province prov left outer join prov.addresss adr " +
" left outer join adr.consumerBrand conb " +
" left outer join conb.consumer con " +
" where conb.brand.brand = ? " +
" group by prov.province" +
"";


I get the following data:

Western Cape : 1

What I need to do is still to receive all the Provinces, but obviously the count of the consumers would be less, as I am now filtering the data. How do I specify that the where part of my query only applies to the consumer con. I will also need to add constraints onto the consumer, gender and age!

I am not quite sure how to achieve this. Any ideas would be appreciated.

Thanks
Jeff Singer


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 8:54 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Hi,

Quote:
What I need to do is still to receive all the Provinces, but obviously the count of the consumers would be less, as I am now filtering the data


I'm not 100% sure what you are trying to achieve.

It seems that what you are trying to achieve is both restrict and project on the same criteria, almost like saying 'give me the provinces where [some criteria] and don't give me the provinces where [the same criteria]'.

In your case you have restricted the province WC as there are no matches in this province.

Remember that you still retrict tuples that have been outer joined. The join type does not affect how the data is restricted by the where clause.

Hope this helps.

Quote:
I will also need to add constraints onto the consumer, gender and age!

Go for it


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

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.