NYCPHP Meetup

NYPHP.org

[nycphp-talk] SQL question

Rob Marscher rmarscher at beaffinitive.com
Tue Jul 24 11:22:12 EDT 2007


OK... I actually looked in the manual this time to get some  
clarification - http://dev.mysql.com/doc/refman/5.0/en/join.html:

"INNER JOIN and ,  (comma) are semantically equivalent in the absence  
of a join condition: both produce a Cartesian product between the  
specified tables (that is, each and every row in the first table is  
joined to each and every row in the second table)."

"Generally, you should use the ON clause for conditions that specify  
how to join tables, and the WHERE clause to restrict which rows you  
want in the result set."

For your question Adrian... I can't find any information backing this  
up... but I'm pretty sure that INNER JOIN...ON and JOIN...ON are  
synonymous.  I did find this "In MySQL, CROSS JOIN is a syntactic  
equivalent to INNER JOIN (they can replace each other). In standard  
SQL, they are not equivalent. INNER JOIN is used with an ON clause,  
CROSS JOIN is used otherwise."  In the join syntax definition they  
show "table_reference [INNER | CROSS] JOIN table_factor  
[join_condition] " -- and that's why I think they're synonymous -- at  
least in MySQL.

I also found the old conversation... now I remember what it was  
about.  I saw an article on contentwithstyle.co.uk saying that INNER  
JOINs were faster and posted it to the list - http://lists.nyphp.org/ 
pipermail/mysql/2006-July/000162.html  Ellen Coen responded that she  
didn't know about the validity of it, but felt that the more  
specific, the better.  That sounded good to me.  http:// 
lists.nyphp.org/pipermail/mysql/2006-July/000163.html  So I guess the  
consensus was just between the two of us... if anyone else can come  
up with a good argument or knows anything more about what the  
database does behind the scenes, feel free to chime in.

Thanks,
Rob




More information about the talk mailing list