Skip to content

SQL query error with MySQL 5.7+ #100

@StinGer-ShoGuN

Description

@StinGer-ShoGuN

Another consequence of my recent updates: now the main page of my killboard displays the following error message.

Database error: Expression #1 of ORDER BY clause is not in SELECT list, references column 'kll.kll_timestamp' which is not in SELECT list; this is incompatible with DISTINCT
SQL: SELECT DISTINCT kll_id FROM ((SELECT kll.* FROM kb3_kills kll INNER JOIN kb3_inv_detail ind ON ind.ind_kll_id = kll.kll_id WHERE ( ind.ind_crp_id IN (1 ) OR ind.ind_plt_id IN (14798 ) ) AND ind.ind_timestamp >= '2018-11-01 00:00:00' AND ind.ind_timestamp <= '2018-11-30 23:59:00' GROUP BY kll.kll_id order by ind.ind_timestamp desc ) UNION (SELECT kll.* FROM kb3_kills kll WHERE ( kll.kll_victim_id in ( 14798 ) OR kll.kll_crp_id in ( 1 ) ) AND kll.kll_timestamp >= '2018-11-01 00:00:00' AND kll.kll_timestamp <= '2018-11-30 23:59:00' order by kll.kll_timestamp desc ) ) kll order by kll.kll_timestamp desc

A solution is to set sql-mode in my.cnf.

[mysqld]
...
sql-mode = ""

A maybe better solution, is the following instead.

[mysqld]
...
sql-mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

An even better solution (i.e. the solution), would be to change the query to include kll_timestamp in the SELECT DISTINCT. It would require more adjustments in the code though. So in common/includes/class.killlist.php, on line 601 (at least, this is the one used for the homepage if I'm correct), change to this:

$ssql = 'SELECT DISTINCT kll_id, kll_timestamp FROM '.$this->sqlinner_.$this->sql_;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions