File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes simple inner join question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "simple inner join question" Watch "simple inner join question" New topic
Author

simple inner join question

jin sun
Ranch Hand

Joined: Feb 16, 2005
Posts: 30
If I want to select somethings only from table 1, but I inner join table 2 anyways, will I recieve an error or anything? Or would the output be the same as if I didn't inner join in the first place?
Phillip Koebbe
Greenhorn

Joined: Jun 22, 2005
Posts: 27
To perform an inner join, you must specify a join condition. For example, suppose I have two tables, t_Employee and t_Department, and DepartmentId is a foreign key in t_Employee. To join the tables, I'd write



If you know that all employees have DepartmentId NOT NULL, then this would functionally be the same as



though if you have no need of t_Department data, either in the result or for search criteria, you're making the database work harder for no reason. To be correct, only join when you have need of a join.

Did that answer your question? If not, please post some code so we can get a better idea of what it is you want to accomplish.

Peace,
Phillip
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1739
    
    2
If I want to select somethings only from table 1, but I inner join table 2 anyways, will I recieve an error or anything?

You won't receive an error. That's a valid query.

The more important question though is whether it's the correct query, given what you're trying to accomplish.

Or would the output be the same as if I didn't inner join in the first place?

Impossible to answer, given what you've told us. It depends entirely on the data in the tables and the conditions in your query.

Here's a quick-and-dirty query that fits your scenario -- two tables inner joined (on a funky inequality, no less!). Only fields from table 1 are selected. The results of this query greatly depend on the value from table 2 in the join condition.

select t1.*
from table1 t1 inner join table2 t2
on t1.transaction_dt > t2.cutoff_dt

So, in other words, we need more info about what you're trying to do in order to provide a better answer.

(Note: before anyone screams "you should have written that query with a subselect, not a join," I know there are several ways of doing what I did, but the point was to write a query that met the original poster's criteria.)
jin sun
Ranch Hand

Joined: Feb 16, 2005
Posts: 30
Thanks for the replies, it was more of hypothetical question that I was looking into. I can see how the output would be an impossible question to answer now without further explanation of the data, unfortunately I do not have any code and can't think of scenario haha.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: simple inner join question
 
Similar Threads
Need more values from Other DB
A query in naming conventions of Oracle Joins
is there a difference between JOIN and INNER JOIN in JPQL ?
Theta Join
counting rows after joins varies