2012-01-30 79 views
1

我使用CodeIgniter進行了以下查詢。我想要一個包含每個組的單個行的列表,如果它是「1」,我希望該行包含liveBlogGroupRecord狀態。Codeigniter SQL Join查詢沒有返回我想要的數據

現在,我要麼只得到行對具有liveBlogGroupRecord=1團,或者,如果我評論說,線路輸出,我得到的多組行同組,因爲blogGroups表中有有liveBlogGroupRecord=0多箇舊值。

$this->db->select('*'); 
$this->db->from('groups'); 
$this->db->join('blogGroups', 'groups.groupID = blogGroups.groupID', 'left'); 
$this->db->where('blogGroups.blogID', $blogID); 
$this->db->where('blogGroups.liveBlogGroupRecord', 1); 
$query = $this->db->get(); 
+0

我認爲如果您向我們展示一些示例數據以及您想要選擇的數據中的哪一行,則會更容易回答此問題。 – 2012-01-31 22:21:02

回答

0

如何添加$this->db->limit(1);$query = $this->db->get();

+0

這將使整個查詢返回一行。 – 2012-01-31 22:19:47

1

小心SELECT *。假設您的blogGroupsgroups表都有一個id(或具有相同名稱的另一列),則只有第一個表會在另一個表中返回。

選擇性地選擇您需要的列。嘗試這樣的事情:

$this->db->select('groups.*'); 

/* And more selectively, whichever elements you have from `blogGroups` that you need (I have no idea what those are) */ 
$this->db->select('blogGroups.name'); 
$this->db->select('blogGroups.description'); 
$this->db->select('blogGroups.category'); 
/* etc */