File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple inner join question

 
jin sun
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1796
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic