Opened 7 years ago
Last modified 4 years 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: | has-patch |
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!
Attachments (1)
Change History (3)
Note: See
TracTickets for help on using
tickets.
Patch replaces
HAVING
withAND
as suggested. My own testing supports @vsvlad's assertion that the updated query returns the same results.I had a look through the codebase and couldn't find any other instances of a query containing
HAVING
withoutGROUP BY
. This appears to be the only case.