0

当我使用这个 sql 时,第一个表中 mem_name 的结果被重复了很多我该如何修复它

    <?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();
?>
4

2 回答 2

1

这是修改后的查询..

<?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();
?>

您可以按查询分组..

Or you can also specify the join criteria

希望它有所帮助。

于 2012-05-18T04:22:53.070 回答
0

您必须指定连接条件。

于 2012-05-16T12:57:49.970 回答