aspose file tools*
The moose likes Object Relational Mapping and the fly likes SQL Join for two different columns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "SQL Join for two different columns" Watch "SQL Join for two different columns" New topic
Author

SQL Join for two different columns

Chandra shekar M
Ranch Hand

Joined: Dec 20, 2006
Posts: 135
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Did you try an OUTER join (default is INNER):
LEFT OUTER JOIN b on a.id = b.id
LEFT OUTER JOIN c on a.id = c.id
Chandra shekar M
Ranch Hand

Joined: Dec 20, 2006
Posts: 135
Hi Koen,
Thanks for the reply. Ouetr join doesnt made any difference. I rewrote the Query like below


The Problem was.
1. First the join was made and then filtering. Filtering logic was specific to the tables b,c and even the joined records use to get dropped off.
Solution
First put the Filtering logic specific to tables b, c before join and then do the generic filtering on the joined records.

This solves the issue.

Thanks
Chandra
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Join for two different columns