• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to select the distinct values

#1
[eluser]Bigil Michael[/eluser]
I want to list the members who have products. Query i have written is given below
Code:
$this->db->select('c.*, m.*, cc.category_name, cs.subcategory_name,  css.sub_subcategory_name');
     $this->db->from('classifieds AS c');
  $this->db->join('classi_sub_subcategory AS css', 'css.sub_subcategory_id = c.sub_subcategory_id');
  $this->db->join('classi_subcategory AS cs', 'cs.subcategory_id = css.subcategory_id');
  $this->db->join('classifieds_category AS cc', 'cc.category_id = cs.category_id');
  $this->db->join('members AS m', 'm.id = c.member_id');
  $this->db->where('c.status', 1);
  
     $result_product = $this->db->get();
  return $result_product->result();


It is running fine but member details are repeating. i want to print the member details name only once.
can any one help me????
thanks in advance....

#2
[eluser]theprodigy[/eluser]
can you show an example of what you are getting, and an example of what you are wanting?

#3
[eluser]NeoArc[/eluser]
I think you want the list of posts of every member.

Run a query in the members table, a second one requesting the classifieds data; and then let PHP do the sorting.


Excuse my english!

#4
[eluser]vitoco[/eluser]
A simple GROUP BY field can help you, and use COUNT( field ) and COUNT( DISTINCT( field ) ) to get summary of items.

Also you can group by several fields using

Code:
GROUP BY
    CONCAT( field_1 , field_2 , ... , field_n )

Slds.

#5
[eluser]Bigil Michael[/eluser]
Thanks for your reply
my problem solved by changing the query like this


Code:
$this->db->select('m.*');
     $this->db->from('cars AS c');
  $this->db->join('cars_sub_subcategory AS css', 'css.sub_subcategory_id = c.sub_subcategory_id');
  $this->db->join('cars_subcategory AS cs', 'cs.subcategory_id = css.subcategory_id');
  $this->db->join('car_category AS cc', 'cc.category_id = cs.category_id');
  $this->db->join('members AS m', 'm.id = c.member_id');
$this->db->distinct();
$result_product = $this->db->get();
return $result_product->result();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.