MySQL Forums
Forum List  »  Optimizer & Parser

Re: LEFT JOIN Issue in 5.0
Posted by: Martin Dubuc
Date: April 10, 2006 03:11PM

Here is a more complete database schema and some data to go with it.

Given the following schema and data input:

CREATE TABLE testjoin1 (
id int(11) unsigned NOT NULL,
sid int(11) unsigned NOT NULL,
PRIMARY KEY (id)
) TYPE=InnoDB;

CREATE TABLE testjoin2 (
id int(11) unsigned NOT NULL,
join2_data int(11) unsigned NOT NULL,
PRIMARY KEY (id)
) TYPE=InnoDB;

CREATE TABLE testjoin3 (
sid int(11) unsigned NOT NULL,
join3_data int(11) unsigned NOT NULL,
PRIMARY KEY (sid)
) TYPE=InnoDB;

INSERT INTO testjoin1 VALUES (1, 2);
INSERT INTO testjoin1 VALUES (2, 3);
INSERT INTO testjoin1 VALUES (3, 3);

INSERT INTO testjoin2 VALUES (1, 11);
INSERT INTO testjoin2 VALUES (2, 22);

INSERT INTO testjoin3 VALUES (2, 32);
INSERT INTO testjoin3 VALUES (3, 33);

I would like to perform the following query:

SELECT testjoin1.id, testjoin1.sid, testjoin2.*, testjoin3.* FROM testjoin1, testjoin3 LEFT JOIN testjoin2 ON testjoin1.id=testjoin2.id WHERE testjoin1.sid=testjoin3.sid;

MySQL 5.0 will complain if such statement is used. MySQL 4.1 will not.

MySQL 4.1 returns:
+----+-----+-----+------------+------+------------+
| id | sid | sid | join3_data | id | join2_data |
+----+-----+-----+------------+------+------------+
| 1 | 2 | 2 | 32 | NULL | NULL |
| 2 | 3 | 3 | 33 | 2 | 22 |
+----+-----+-----+------------+------+------------+

Options: ReplyQuote


Subject
Views
Written By
Posted
3665
April 10, 2006 10:28AM
1952
April 10, 2006 10:37AM
1900
April 10, 2006 11:38AM
1993
April 10, 2006 12:50PM
Re: LEFT JOIN Issue in 5.0
2032
April 10, 2006 03:11PM
1849
April 10, 2006 03:24PM
1834
April 11, 2006 07:34AM
1932
April 11, 2006 07:34AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.