Bug #32490 MySQL doesn't make any difference if UNION is in subselect or no
Submitted: 19 Nov 2007 10:36 Modified: 10 Dec 2007 22:22
Reporter: Victoria Reznichenko Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1,5.0,5.1 OS:Any
Assigned to: Assigned Account CPU Architecture:Any
Tags: bfsm_2007_12_06

[19 Nov 2007 10:36] Victoria Reznichenko
Description:
With UNION only last SELECT can have INTO, though if UNION is in FROM clause MySQL stil generates an error.

mysql> select count(id) into @cnt from (select id from u1 union select id from u2) as u;
ERROR 1221 (HY000): Incorrect usage of UNION and INTO

How to repeat:
CREATE TABLE `u1` (
  `id` int(11) default NULL
) ENGINE=MyISAM;
CREATE TABLE `u2` (
  `id` int(11) default NULL
) ENGINE=MyISAM;
SELECT COUNT(id) into @cnt FROM (SELECT id FROM u1 UNION SELECT id FROM u2) as u;

Suggested fix:
It should be either fixed or documented.
[10 Dec 2007 22:22] Trudy Pelzer
This is a duplicate of bug#32858.