Reputation: 87
when i use this sql the result of mem_name from the first table is repated a lot how can i fix it
<?php
$sql="SELECT mc.mc_id,mc.mc_role,mc.mc_order,mc.mc_order IS NULL AS isnull, mem.*
FROM $this->memberCatsTableName mc, $this->tableName mem
WHERE mc.cat_id=$cat_id $where AND mc.member_id=mem.mem_id or mem.mem_name='$mem_name'
ORDER BY isnull ASC, mc.mc_order ASC";
$query = $this->db->query($sql);
return $query->result_array();
?>
Upvotes: 0
Views: 168
Reputation: 4446
here is modified query..
<?php
$sql="SELECT mc.mc_id,mc.mc_role,mc.mc_order,mc.mc_order IS NULL AS isnull, mem.*
FROM $this->memberCatsTableName mc, $this->tableName mem
WHERE mc.cat_id=$cat_id $where AND mc.member_id=mem.mem_id or mem.mem_name='$mem_name'
Group by mem.mem_name
ORDER BY isnull ASC, mc.mc_order ASC";
$query = $this->db->query($sql);
return $query->result_array();
?>
You can group by the query..
Or you can also specify the join criteria
Hope its helped.
Upvotes: 1