-->
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: How do I do a left outer join without left->right relation?
PostPosted: Tue Dec 18, 2012 12:49 pm 
Newbie

Joined: Tue Dec 18, 2012 12:33 pm
Posts: 1
I have two tables I need to join. The left table does not have a relation to the right table, but the right table DOES have a relation back to the left table. For the life of me I cannot figure out the syntax, I keep getting an error "Path expected for join!". I don't know what that means.

For the moment, here's what I'm trying to do:

SELECT
host.address,session.openedAt,session.closedAt
FROM
Hosts as host
LEFT OUTER JOIN
Sessions as session
WHERE (session.relHost.id = host.id AND session.closedAt is null)

This doesn't work at all, I keep getting the query error: "Path Expected For Join!". But then, I'm not even sure this will get me my intended results. The session table may have multiple (open and closed) sessions, each pointing to the same relHost. What I want is a table that has every line of the host table (with no duplicates), along with a boolean column indicating whether there is at least one open session for that host. (session.opened != null and session.closed == null)

I'm really at a loss how to do this. (My MySQL knowledge is limited, my HQL even moreso). I've tried every bit of syntax I could find on the internet, and I can't even get the most basic of joins to work, so I'm apparently missing some concept here. (It doesn't help that none of the examples I found had before and after tables to show what the syntax actually does)

Any help would be greatly appreciated.

Charles.


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.