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」);' –