如何在我的查询CODEIGNITER中使用DISTINCT [英] how to use DISTINCT here in my query CODEIGNITER

查看:165
本文介绍了如何在我的查询CODEIGNITER中使用DISTINCT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$q = $this->db->select('
             books.title,
             reserved_books.id,
             reserved_books.isbn, 
             reserved_books.price,
             reserved_books.item_sold,
             reserved_books.date_sold,
             reserved_books.total_amount
            ')
        ->from('reserved_books')
        ->join('books','reserved_books.isbn= books.isbn')
        ->limit($limit,$offset);

如何在查询中使用"distinct"? reserved_books.isbn是唯一的.

how can i use distinct here in my query? reserved_books.isbn is the unique one.

推荐答案

尝试以下方法:

$this->db->distinct();

,但Distinct并不总是有效.您应该添加->group_by("name_of_the_column_which_needs_to_be unique");

but Distinct will not always work. You should add ->group_by("name_of_the_column_which_needs_to_be unique");

$this->db->group_by('column_name');

这篇关于如何在我的查询CODEIGNITER中使用DISTINCT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆