Bug #70461 incorrect select max not null

Submitted: 29 Sep 2013 2:52 Modified: 8 Oct 2013 19:08
Reporter: Patrik pomelli Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Data Types Severity:S2 (Serious)
Version:5.5.20 OS:Windows (xp32)
Assigned to: CPU Architecture:Any
Tags: query max

[29 Sep 2013 2:52] Patrik pomelli
Description:
incorrect row select if use "not null" and report promisque data

SELECT pq_ho, MAX(pq_data) FROM serv_site_memu WHERE pq_ho IS NOT NULL UNION
SELECT pq_ho, MAX(pq_data) FROM serv_site_memu;

pq_ho 	MAX(pq_data)
12 	2013-09-28
16 	2013-09-28

How to repeat:

CREATE TABLE IF NOT EXISTS `serv_site_memu` (
  `PQ` bigint(11) unsigned NOT NULL AUTO_INCREMENT,
  `pq_po` bigint(11) unsigned NOT NULL,
  `pq_titolo` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `pq_wf` bigint(11) unsigned DEFAULT NULL COMMENT 'icona wind_icons',
  `pq_data` date DEFAULT NULL,
  `pq_text` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'se ci sono altre infomazioni aggiuntive sul menu',
  `pq_tu` bigint(11) unsigned DEFAULT NULL COMMENT 'gruppo che accede',
  `pq_ho` bigint(11) unsigned DEFAULT NULL COMMENT 'immagine locandina ',
  `pq_ut` bigint(11) unsigned DEFAULT NULL COMMENT 'utente che ha inserito',
  `pq_order` smallint(1) unsigned DEFAULT NULL,
  `pq_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`PQ`),
  KEY `pq_po` (`pq_po`),
  KEY `Index 3` (`pq_wf`),
  KEY `Index 4` (`pq_tu`),
  KEY `Index 5` (`pq_ho`),
  KEY `Index 6` (`pq_ut`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='menu delle pagine' AUTO_INCREMENT=13 ;

--
-- Dump dei dati per la tabella `serv_site_memu`
--

INSERT INTO `serv_site_memu` (`PQ`, `pq_po`, `pq_titolo`, `pq_wf`, `pq_data`, `pq_text`, `pq_tu`, `pq_ho`, `pq_ut`, `pq_order`, `pq_time`) VALUES
(1, 36, 'xyvYXVXYV33vcc', NULL, '2013-09-28', '', NULL, 16, 1, NULL, '2013-09-26 01:17:04'),
(2, 36, 'gattone', 839, '2013-09-26', '', NULL, 12, 1, NULL, '2013-09-26 01:34:10'),
(4, 36, 'wf2 null modi', NULL, '2013-09-27', '', NULL, NULL, 1, NULL, '2013-09-26 03:14:00'),
(5, 36, 'reload pq', NULL, '2013-09-27', '', NULL, NULL, 1, NULL, '2013-09-26 03:17:18'),
(6, 36, 'reload pq', NULL, '2013-09-27', '', NULL, NULL, 1, NULL, '2013-09-26 03:17:20'),
(7, 36, 'reload pq', NULL, '2013-09-27', '', NULL, NULL, 1, NULL, '2013-09-26 03:17:22'),
(8, 36, 'picche', NULL, '2013-09-27', '', NULL, NULL, 1, NULL, '2013-09-26 03:17:58'),
(9, 36, 'quo', NULL, '2013-09-27', '', NULL, NULL, 1, NULL, '2013-09-26 03:19:10'),
(10, 36, 'xxxxx', NULL, '2013-09-27', '', NULL, NULL, 1, NULL, '2013-09-26 03:19:39'),
(11, 36, 'xxxxx', NULL, '2013-09-27', '', NULL, NULL, 1, NULL, '2013-09-26 03:19:47'),
(12, 36, 'xxxxx', NULL, '2013-09-27', '', NULL, NULL, 1, NULL, '2013-09-26 03:19:47');
[8 Oct 2013 19:08] Sveta Smirnova
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

You use aggregate function MAX, select other column and do not use GROUP BY clause. MySQL allows such queries, but does not guarantee which rows will be returned: http://dev.mysql.com/doc/refman/5.6/en/server-sql-mode.html#sqlmode_only_full_group_by

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
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.