$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);
how can i use distinct here in my query? reserved_books.isbn is the unique one.
You can use below mentioned query. $query = $this->db->group_by('category_master. Category_Id,business_profile_details. Business_Id');
The SQL SELECT DISTINCT Statement The SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
The LARAVEL ELOQUENT query would be. Meta::distinct()->whereNotNull('meta_value')->get(['meta_value']); 4. A more advanced version of the DISTINCT query would be one where you would want to fetch data from separate columns while still maintaining a value from the column to be distinct.
The SQL DISTINCT keyword is used in conjunction with the SELECT statement to eliminate all the duplicate records and fetching only unique records. There may be a situation when you have multiple duplicate records in a table.
Try Below:
$this->db->distinct();
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With