introduction screenshots faq forum blog modules components download
Please use the search function and/or read the FAQ first.

Go to Topic: PreviousNext
Go to: Message ListNew TopicSearchLog InPrint View

Strange behaviour in certain MySQL queries



Posted by: Lucius
January 11, 2008 01:00AM
I've encountered a problem in EasyPHP 2.0b1 with MySQL queries using both left joins and aliases.
for example, if I have this query:

SELECT a.*,b.field1,c.field2
FROM table1 AS a, table2 AS b
LEFT JOIN table3 AS c ON c.id=a.idtable3
WHERE a.id='x' AND b.id=a.field3

I get this error:

#1054 - Unknown column 'a.idtable3' in 'on clause'

even if that field DOES exist!
While if I switch the FROM argument like this: 'FROM table2 AS b, table1 AS a' the query works correctly.
Does anyone know the reason of this beavior? Is it just a MySQL bug?
NOTE: this didn't happen in EasyPHP 1.9

--
Luciano S.
luciano AT allforweb DOT biz
Options: ReplyQuote
Posted by: ptirhiik
January 12, 2008 12:18PM
With recent mysql version, the sql language compliancy has been enforced. Therefore, when you write:

SELECT a.* FROM table1 a
LEFT JOIN table2 b ON b.key = a.key
LEFT JOIN table3 c ON c.key = b.key

It is understood as:
SELECT a.* FROM table1 a
LEFT JOIN (table2 b ON b.key = a.key
LEFT JOIN table3 c ON c.key = b.key)

And what you want is:
SELECT a.* FROM ((table1 a
LEFT JOIN table2 b ON b.key = a.key)
LEFT JOIN table3 c ON c.key = a.key)

In other words, without parenthesis, you get:
table1 x T2 having T2 = table2 x table3

where you want
T1 x table3 having T1 = table1 x table2



Edited 1 time(s). Last edit at 01/12/2008 12:22PM by ptirhiik.
Options: ReplyQuote
Posted by: Lucius
February 04, 2008 06:30PM
thank you very much!
your help has been invaluable..

--
Luciano S.
luciano AT allforweb DOT biz
Options: ReplyQuote


Go to: Message ListSearchLog In
Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.