How to Write Distinct Query in CodeIgniter?

Today, We want to share with you distinct codeigniter.In this post we will show you codeigniter get_where multiple conditions, hear for sql unique count and use distinct in sql we will give you demo and example for implement.In this post, we will learn about Sql Unique Count And Use Distinct In Sql with an example.

get_where codeigniter Code Example

Distinct in Codeigniter Query

$where_array = array(
               'email'=>'[email protected]',
               'status'=>'1'
              );
$shop_name = "members";
$limit = 10;
$offset = 0;
$this->db->distinct();
$query = $this->db->get_where($shop_name,$where_array, $limit, $offset);

Using distinct() Method

$this->db->select('Level');
$this->db->distinct();
$query = $this->db->get('Members');

// Generates SQL String
// SELECT DISTINCT `Level` FROM `Members`;

Using DISTINCT Keyword in Select() Method:

$this->db->select('DISTINCT(Level)');
$query = $this->db->get('Members');

// Generates SQL String
// SELECT DISTINCT(Level) FROM `Members`;

distinct() Query in Codeigniter

$this->db->distinct();
$this->db->get('shop'); 
// Produces: SELECT DISTINCT * FROM shop

Example:

$record = '123';

$this->db->distinct();

$this->db->select('accessid');

$this->db->where('record', $record); 

$query = $this->db->get('accesslog');

get Num Rows
$query->num_rows();

I hope you get an idea about distinct codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.