If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > A basic question about JOINs

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-10, 03:24
ororo ororo is offline
Registered User
 
Join Date: Nov 2010
Posts: 8
Question A basic question about JOINs

What is the difference betweeen:

SELECT a.*,b.* FROM a, b WHERE a.somefield = b.otherfield

and

SELECT a.*,b.* FROM a JOIN b ON a.somefield = b.otherfield

???

Thank you!


EDIT: Sorry, this is the wrong forum, I meant to write in the "beginners" forum...
Reply With Quote
  #2 (permalink)  
Old 11-10-10, 05:12
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by ororo View Post
What is the difference betweeen:
one of them is an inner join written using the older, deprecated, comma-style join syntax, while the other one is an inner join written using explicit JOIN syntax
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-10-10, 10:19
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by r937 View Post
one of them is an inner join written using the older, deprecated, comma-style join syntax, while the other one is an inner join written using explicit JOIN syntax
Deprecated? You are completely wrong about that. Look at a DB2 explain report (query re-write section) and you will see the "explicit join" syntax will be re-written to the "old" style.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 11-10-10, 10:20
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by ororo View Post
What is the difference betweeen:

SELECT a.*,b.* FROM a, b WHERE a.somefield = b.otherfield

and

SELECT a.*,b.* FROM a JOIN b ON a.somefield = b.otherfield

???

Thank you!


EDIT: Sorry, this is the wrong forum, I meant to write in the "beginners" forum...
There is no difference.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 11-10-10, 10:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by Marcus_A View Post
Deprecated?
did i say that? i meant "disrespected"

okay, maybe not deprecated as in an official announcement from the vendor that the feature will no longer be supported as of such-and-such version...

but rather deprecated as in you shouldn't do it this way, even if it works

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 11-10-10, 10:25
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Quote:
Originally Posted by Marcus_A View Post
Deprecated? You are completely wrong about that. Look at a DB2 explain report (query re-write section) and you will see the "explicit join" syntax will be re-written to the "old" style.
I like the "old" style. Easier to understand and observe from the first glance. Simplicity at its finest.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #7 (permalink)  
Old 11-10-10, 11:20
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by r937 View Post
did i say that? i meant "disrespected"

okay, maybe not deprecated as in an official announcement from the vendor that the feature will no longer be supported as of such-and-such version...

but rather deprecated as in you shouldn't do it this way, even if it works

No, that is not right either. I always use the old style, and always will. So does the DB2 query rewrite and optimizer. The "old" style will always work, forever.

Explicit JOIN keywords are for donkeys.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #8 (permalink)  
Old 11-10-10, 11:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by Marcus_A View Post
Explicit JOIN keywords are for donkeys.
and outer joins, presumably

also, rudeness does not look very good on an IBMer, but it is not altogether unexpected, either

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 11-10-10, 14:06
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by r937 View Post
and outer joins, presumably

also, rudeness does not look very good on an IBMer, but it is not altogether unexpected, either

I am not a IBM employee. But I was not being rude, just explaining what I think. I take your comments about deprecated code (that will infact will never be deprecated) as more than a little insulting to those of us who prefer the "old" way.

95% of the time, extensive use of OUTER JOINs can cause very poor SQL performance and is often an indication of poor database design (usually normalizing beyond 3NF). In many cases, these can also usually be written without explict OUTER JOIN syntax also.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #10 (permalink)  
Old 11-10-10, 14:51
TallCowboy0614 TallCowboy0614 is offline
Throwin' the steel to SQL
 
Join Date: Feb 2004
Location: Marina Del Rey, CA
Posts: 3,663
Quote:
Originally Posted by Cougar8000 View Post
I like the "old" style. Easier to understand and observe from the first glance. Simplicity at its finest.
disagree with impunity. If you want to join tables, do it EXPLICITLY. To me, implicit joins are lazy, weak, and generally written by sub-par developers. I will arm-wrestle on this point. For houses. Or hell, wives. Implicit joins are for girley-boys that would blindely kiss across the dividers in barroom restrooms.
__________________
aka "Paul"
Non est ei similis.

I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them
Reply With Quote
  #11 (permalink)  
Old 11-10-10, 14:53
TallCowboy0614 TallCowboy0614 is offline
Throwin' the steel to SQL
 
Join Date: Feb 2004
Location: Marina Del Rey, CA
Posts: 3,663
Quote:
Originally Posted by Marcus_A View Post
No, that is not right either. I always use the old style, and always will. So does the DB2 query rewrite and optimizer. The "old" style will always work, forever.

Explicit JOIN keywords are for donkeys.
I must state here for the record, that those that hold this viewpoint are indeed , SQL donkey's arses, and will never work in a company in which I am employed.

If you can't be explicit, then you should be unemployed....or at minimum, be tossing french fries across the counter.
__________________
aka "Paul"
Non est ei similis.

I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them
Reply With Quote
  #12 (permalink)  
Old 11-10-10, 16:21
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by TallCowboy0614 View Post
I must state here for the record, that those that hold this viewpoint are indeed , SQL donkey's arses, and will never work in a company in which I am employed.

If you can't be explicit, then you should be unemployed....or at minimum, be tossing french fries across the counter.
I never said anything about "arses".

Do you have something against donkeys? The Democratic Party has had the donkey as their mascot for more than 150 years.

Anyway, in poker terms, donkey is a naive or inexperienced person, not an arse.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #13 (permalink)  
Old 11-10-10, 17:17
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Quote:
Originally Posted by Cougar8000 View Post
I like the "old" style. Easier to understand and observe from the first glance. Simplicity at its finest.
I'm with you on this one, Cougar. I'm used to seeing the "older comma-style" / "implicit join" syntax and find it easier to understand.
Reply With Quote
  #14 (permalink)  
Old 11-10-10, 17:20
TallCowboy0614 TallCowboy0614 is offline
Throwin' the steel to SQL
 
Join Date: Feb 2004
Location: Marina Del Rey, CA
Posts: 3,663
Quote:
Originally Posted by Marcus_A View Post
Anyway, in poker terms, donkey is a naive or inexperienced person, not an arse.
Even using your definition of the moniker, I still feel my comment is spot on. Why would someone use implicit context when explicit is available? Isn't it better to have People Who Come Later understand what you are trying to do than it is to have someone think "Hmmm...looks like they mean to do this..."?

Color me jaded after 35+ years in the industry, but I tell ya...I would STRONGLY argue that in pretty much ANY 'puter-nerd endeavor, explicit is like a billion times more valuable than implicit.

But that is just me.
__________________
aka "Paul"
Non est ei similis.

I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them
Reply With Quote
  #15 (permalink)  
Old 11-10-10, 17:47
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by TallCowboy0614 View Post
Even using your definition of the moniker, I still feel my comment is spot on. Why would someone use implicit context when explicit is available? Isn't it better to have People Who Come Later understand what you are trying to do than it is to have someone think "Hmmm...looks like they mean to do this..."?

Color me jaded after 35+ years in the industry, but I tell ya...I would STRONGLY argue that in pretty much ANY 'puter-nerd endeavor, explicit is like a billion times more valuable than implicit.

But that is just me.
I can tell you from my experience (yours may be different) that when I see an SQL statement written by someone else with a lot of explicit JOIN keywords, it usually extremely complex and if there are multiple WHERE clauses and multiple parenthesis (which there often are) then it is very difficult to understand how the WHERE clauses are to be applied. I have always been able to understand a join that is written without a JOIN keyword.

I spend a lot of time looking at other people's SQL when I do SQL Snapshots and performance tuning.

The DB2 query re-write and optimizer converts all of the this JOIN stuff to the "old style" join syntax, so anyone who says it is "going away" or is "to be discouraged" is out of line.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On