Welcome Guest, Not a member yet? Register   Sign In
database error when using DISTINCT and ORDER BY
#1

hello everyone 

i am new to code igniter and got stuck in one query i want to get distinct id from database order it by id

my code is 

PHP Code:
$this->db->select('message_user_id, message_user_name');
$this->db->distinct("message_user_id");
$this->db->order_by("message_id");
$this->db->get('cms_inbox'); 


i get this error when i run it  i am using wamp with php 7 and mysql 5.7

Code:
Error Number: 3065
[color=#4f5155][size=small]Expression #1 of ORDER BY clause is not in SELECT list, references column 'test.cms_inbox.message_id' which is not in SELECT list; this is incompatible with DISTINCT[/size][/color]
[color=#4f5155][size=small]SELECT DISTINCT `message_user_id`, `message_user_name` FROM `cms_inbox` ORDER BY `message_id`[/size][/color]
[color=#4f5155][size=small]Filename: G:/wamp/www/system/database/DB_driver.php[/size][/color]
Line Number: 691


how can i fix it please help me
Reply


Messages In This Thread
database error when using DISTINCT and ORDER BY - by corey - 05-04-2017, 11:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB