Bug #22 | double IN subselect incorrect results | ||
---|---|---|---|
Submitted: | 5 Jan 2003 18:20 | Modified: | 17 May 2004 19:17 |
Reporter: | Oleksandr Byelkin | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 4.1 | OS: | Any (any) |
Assigned to: | Oleksandr Byelkin | CPU Architecture: | Any |
[5 Jan 2003 18:20]
Oleksandr Byelkin
[28 Jan 2003 10:28]
MySQL Developer
in my current developent tree this bug is gone
[17 May 2004 18:49]
Mark Fowler
I've just experienced this bug on 4.1.1. Has the bug reoccured, or did the changes that fix this that Oleksandr Byelkin mentioned never migrate into the current alpha? Mark Fowler mark@twoshortplanks.com
[17 May 2004 18:52]
Mark Fowler
To confirm, I'm trying this: Create the table: CREATE TABLE `mytable` ( `id` int(11) default NULL, `colour` text, `value` int(11) default NULL ) TYPE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `mytable` (`id`,`colour`,`value`) VALUES ("1","blue","100"); INSERT INTO `mytable` (`id`,`colour`,`value`) VALUES ("2","blue","500"); INSERT INTO `mytable` (`id`,`colour`,`value`) VALUES ("3","red","100"); INSERT INTO `mytable` (`id`,`colour`,`value`) VALUES ("4","red","500"); INSERT INTO `mytable` (`id`,`colour`,`value`) VALUES ("5","green","100"); INSERT INTO `mytable` (`id`,`colour`,`value`) VALUES ("6","green","500"); Run the query: SELECT * FROM mytable WHERE id IN (SELECT id FROM mytable WHERE colour = "blue") AND id IN (SELECT id FROM mytable WHERE value < 400); Expected result: 1, blue, 100 Actual result with Mysql 4.1.1-alpha: all rows from table
[17 May 2004 18:57]
Mark Fowler
Rearanging the brackets in the double IN to match Oleksandr Byelkin's structure works. So this: SELECT * FROM mytable WHERE id IN (SELECT id FROM mytable WHERE colour = "blue" AND id IN (SELECT id FROM mytable WHERE value < 400)); Returns the expected results. However, the previous SQL (without the nested INs) really should work. Maybe this should therefore be submitted as a seperate bug. Please advise if that's the case.
[17 May 2004 19:17]
Alexander Keremidarski
Both queries work well for me: mysql> SELECT VERSION(); +-----------------------+ | VERSION() | +-----------------------+ | 4.1.2-alpha-debug-log | +-----------------------+ This is pre-4.1.2 from our source tree. mysql> SELECT * FROM mytable -> WHERE id IN (SELECT id FROM mytable WHERE colour = "blue") -> AND id IN (SELECT id FROM mytable WHERE value < 400); +------+--------+-------+ | id | colour | value | +------+--------+-------+ | 1 | blue | 100 | +------+--------+-------+ 1 row in set (0.04 sec) mysql> SELECT * FROM mytable -> WHERE id IN (SELECT id FROM mytable -> WHERE colour = "blue" -> AND id IN (SELECT id FROM mytable WHERE value < 400)); +------+--------+-------+ | id | colour | value | +------+--------+-------+ | 1 | blue | 100 | +------+--------+-------+