-->
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: Query with sub query
PostPosted: Tue Feb 17, 2009 10:54 am 
Newbie

Joined: Mon Jul 21, 2008 5:40 am
Posts: 16
Hi,

I have two related tables:

public class User {
private Long id;
String Code;
}

public class Leader {
Long id;
private User user;
...
}


Two things I'd like to do:

1. return a list of Users that are not in the Leader table;

session.createQuery("from User u where ( not in (select p.usr from Leader p))").list(); // this does not work


2. return a list of Code that belong to a user not in the Leader table;
session.createQuery("select u.code from Usr u where ( not in (select p.usr from Leader p))").list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 11:34 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
1.
Code:
"select u from User u where u.id not in (select l.user.id from Leader l)"


2.
Code:
"select u.code from User u where u.id not in (select l.user.id from Leader l)"


Rating is welcome. ;-)

_________________
-----------------
Need advanced help? http://www.viada.eu


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.