[wp-trac] [WordPress Trac] #43630: HAVING without GROUP BY in /wp-admin/includes/template.php

WordPress Trac noreply at wordpress.org
Sun Mar 25 16:09:44 UTC 2018


#43630: HAVING without GROUP BY in /wp-admin/includes/template.php
----------------------------+-----------------------------
 Reporter:  vsvlad          |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Administration  |    Version:  4.9.4
 Severity:  normal          |   Keywords:
  Focuses:  template        |
----------------------------+-----------------------------
 I found in file /wp-admin/includes/template.php, that used HAVING without
 GROUP BY. It's syntax correct for MySQL

 {{{#!php
 <?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
 <?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!

--
Ticket URL: <https://core.trac.wordpress.org/ticket/43630>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list