0
有一个带有“标记”列的表 - 我想从我的表中选择10个随机记录,其中没有一个记录共享相同的标签(每个记录都有唯一的标签)。我将如何做到这一点?这是我当前的查询:从表中选择随机数的记录,其中列值不重复用于mysql中的结果集
$this->db->select('extra_imagery');
$this->db->where('cat', '4');
//need something like: $this->db->where('tag',IS UNIQUE);
$this->db->limit($this->config->item('imagery-limit'));
$this->db->order_by('extra_imagery.id','RANDOM');
加上'DISTINCT'和/或'GROUP BY'到您的查询。 –
就这样 - '$ this-> db-> distinct()'?或者我需要指定哪个列需要是不同的?似乎应该有一个选项来说'$ this-> db-> distinct('tag')' – mheavers
https://ellislab.com/codeigniter/user-guide/database/active_record.html - '$ this-> db-> distinct();' - '$ this-> db-> group_by(“title”);' –