MySQLTalk.org Forum Index MySQLTalk.org
MYSQL discussions groups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

JOIN problem

 
Post new topic   Reply to topic    MySQLTalk.org Forum Index -> MySQL Bugs
View previous topic :: View next topic  
Author Message
Michael Ribbons
Guest





PostPosted: Tue Nov 28, 2006 11:10 am    Post subject: JOIN problem Reply with quote



Hi, not sure if this is a bug or a feature added with the changes for nested JOINs,
this code works fine under 4.0.24, but 2nd last query fails under 5.0.26.

Please observe the following sql:

CREATE DATABASE DB_JOIN_TEST;USE DB_JOIN_TEST;
CREATE TABLE ta ( ta_id int default 0 );CREATE TABLE tb ( tb_id int default 0 );CREATE TABLE tc ( tc_id int default 0 );

SELECT ta.* FROM ta LEFT JOIN tb ON tb.tb_id = ta.ta_id;
SELECT ta.* FROM ta, tc LEFT JOIN tb ON tb.tb_id = ta.ta_id;
ERROR 1054 (42S22): Unknown column 'ta.ta_id' in 'on clause'
SELECT ta.* FROM tc, ta LEFT JOIN tb ON tb.tb_id = ta.ta_id;

DROP DATABASE DB_JOIN TEST;

My problem is that a more complicated version of this bug exists in production software where it's not possible to change the FROM clause to put ta next to JOIN (if that's what is actually solving the error....)


Regards
_________________________________________________________________
Be one of the first to try Windows Live Mail.
http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d
Back to top
Hartmut Holzgraefe
Guest





PostPosted: Tue Nov 28, 2006 11:10 am    Post subject: Re: JOIN problem Reply with quote



Michael Ribbons wrote:
Quote:
Hi, not sure if this is a bug or a feature added with the changes for nested JOINs,
this code works fine under 4.0.24, but 2nd last query fails under 5.0.26.

JOIN behavior was changed starting with MySQL 5.0.12 to become
more ANSI compliant, check the "JOIN Syntax" manual page for
"Join Processing Changes in MySQL 5.0.12"

vhttp://dev.mysql.com/doc/refman/5.0/en/join.html



Quote:
Please observe the following sql:
[...]
SELECT ta.* FROM ta, tc LEFT JOIN tb ON tb.tb_id = ta.ta_id;
ERROR 1054 (42S22): Unknown column 'ta.ta_id' in 'on clause'

* Previously, the comma operator (,) and JOIN both had the same
precedence, so the join expression t1, t2 JOIN t3 was interpreted
as ((t1, t2) JOIN t3). Now JOIN has higher precedence, so the
expression is interpreted as (t1, (t2 JOIN t3)). This change
affects statements that use an ON clause, because that clause
can refer only to columns in the operands of the join, and the
change in precedence changes interpretation of what those
operands are.

so rewriting the query like this should solve your problem:

SELECT ta.* FROM (ta, tc) LEFT JOIN tb ON tb.tb_id = ta.ta_id;
^ ^


--
Hartmut Holzgraefe, Senior Support Engineer .
MySQL AB, www.mysql.com
Back to top
Valeriy Kravchuk
Guest





PostPosted: Tue Nov 28, 2006 11:10 am    Post subject: Re: JOIN problem Reply with quote



Hi Michael,

This:

SELECT ta.* FROM ta, tc LEFT JOIN tb ON tb.tb_id = ta.ta_id;
ERROR 1054 (42S22): Unknown column 'ta.ta_id' in 'on clause'

is not a bug, but a result of changing JOIN behaviour in 5.0.12 and
following versions. Please, read the manual,
http://dev.mysql.com/doc/refman/5.0/en/join.html:

" However, the precedence of the comma operator is less than than of INNER
JOIN, CROSS JOIN, LEFT JOIN, and so on. If you mix comma joins with the
other join types when there is a join condition, an error of the form
Unknown column 'col_name' in 'on clause' may occur."

Best regards,
--
Valeriy Kravchuk, Support Engineer
MySQL AB, Kiev, Ukraine, www.mysql.com

Are you MySQL certified? www.mysql.com/certification
Back to top
Michael Ribbons
Guest





PostPosted: Tue Nov 28, 2006 11:10 am    Post subject: RE: JOIN problem Reply with quote

Thanks, and thanks to Valeriy Kravchuk too.

Quote:
Date: Tue, 28 Nov 2006 11:06:22 +0100> From: hartmut (AT) mysql (DOT) com> To: mribbons (AT) hotmail (DOT) com> CC: bugs (AT) lists (DOT) mysql.com> Subject: Re: JOIN problem> > Michael Ribbons wrote:> > Hi, not sure if this is a bug or a feature added with the changes for nested JOINs, > > this code works fine under 4.0.24, but 2nd last query fails under 5.0.26.> > JOIN behavior was changed starting with MySQL 5.0.12 to become> more ANSI compliant, check the "JOIN Syntax" manual page for> "Join Processing Changes in MySQL 5.0.12"> > vhttp://dev.mysql.com/doc/refman/5.0/en/join.html> > > > > Please observe the following sql:> [...]> > SELECT ta.* FROM ta, tc LEFT JOIN tb ON tb.tb_id = ta.ta_id;> > ERROR 1054 (42S22): Unknown column 'ta.ta_id' in 'on clause'> > * Previously, the comma operator (,) and JOIN both had the same> precedence, so the join expression t1, t2 JOIN t3 was interpreted> as ((t1, t2) JOIN t3). Now JOIN has higher precedence, so the> expression is interpreted as (t1, (t2 JOIN t3)). This change> affects statements that use an ON clause, because that clause> can refer only to columns in the operands of the join, and the> change in precedence changes interpretation of what those> operands are.> > so rewriting the query like this should solve your problem:> > SELECT ta.* FROM (ta, tc) LEFT JOIN tb ON tb.tb_id = ta.ta_id;> ^ ^> > > -- > Hartmut Holzgraefe, Senior Support Engineer .> MySQL AB, www.mysql.com
_________________________________________________________________

Be one of the first to try Windows Live Mail.
http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d
Back to top
Display posts from previous:   
Post new topic   Reply to topic    MySQLTalk.org Forum Index -> MySQL Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.