WordPress.org

Make WordPress Core

Opened 3 months ago

#43630 new defect (bug)

HAVING without GROUP BY in /wp-admin/includes/template.php

Reported by: vsvlad Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.4
Component: Administration Keywords:
Focuses: template Cc:

Description

I found in file /wp-admin/includes/template.php, that used HAVING without GROUP BY. It's syntax correct for MySQL

<?php
614   $sql = "SELECT DISTINCT meta_key
615                             FROM $wpdb->postmeta
616                             WHERE meta_key NOT BETWEEN '_' AND '_z'
617                             HAVING meta_key NOT LIKE %s
618                             ORDER BY meta_key
619                             LIMIT %d";

Official MySQL doc say: "HAVING is merged with WHERE if you do not use GROUP BY or aggregate functions (COUNT(), MIN(), and so on).

But this incorrect for other databases. Such as SQLite say it's wrong, when using WP with it.

Maybe in this case, need replace 'HAVING' on 'AND'? After replace like:

<?php
SELECT DISTINCT meta_key
FROM $wpdb->postmeta
WHERE meta_key NOT BETWEEN '_' AND '_z'
  AND meta_key NOT LIKE %s
ORDER BY meta_key
LIMIT %d

It's work!

Change History (0)

Note: See TracTickets for help on using tickets.