• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

simple inner join question

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic