简体   繁体   中英

Codeigniter Database Error 1055 - isn't in GROUP BY

$query = $this->db->group_by('hs_tktno');
$query = $this->db->where('hs_toid', $id);
$query = $this->db->order_by('hs_id', "desc");
$query = $this->db->get('table');
$data["list"] =  $query->result();

Im Getting the following error when i try to excute the above code any ideas?

Error Number: 1055

'dbname.table.hs_id' isn't in GROUP BY

SELECT * FROM ( table ) WHERE hs_status = '0' GROUP BY hs_tktno

Didn't understood much by question, but your query written is wrong. It should be like this,

$this->db->group_by('hs_tktno');
$this->db->where('hs_toid', $id);
$this->db->order_by('hs_id', "desc");
$query = $this->db->get('table');

return $query->result();

I also had this issue, the solution that I found was to change your my.cnf or my-default.cnf in your server. For my case, I am using mac, this file can be found at /usr/local/mysql/support-files/

Steps to produce solution:

  1. Open Terminal
  2. cd /usr/local/mysql/support-files/
  3. sudo vim my.cnf
  4. scroll all the way to the bottom and press i to insert
  5. replace the existing slq_mode with sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
  6. press esc to exit input mode
  7. type :wq to save and close vim
  8. now restart your mysql with sudo /usr/local/mysql/support-files/mysql.server restart or sudo service mysql restart
  9. All done and you are set to enjoy your coding. Have fun :)

For some who couldn't find their my.cnf file. Please refer to this for Mark B answer. This will help you to find your my.cnf .

If you only have my-default.cnf, you could just copy it to ~/.my.cnf with the command sudo cp /usr/local/mysql/support-files/my-default.cnf ~/.my.cnf and remember to restart after that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM