house_id|house_name|status
1 | A | 1
2 | B | 1
3 | C | 0
4 | D | 1
5 | E | 1
6 | F | 1
house_id| image
2 | img1.jpg
2 | img2.jpg
1 | img3.jpg
4 | img4.jpg
1 | img5.jpg
4 | img6.jpg
3 | img7.jpg
house_id|house_name|image
6 | F |NULL
5 | E |NULL
4 | D |img4.jpg
2 | B |img1.jpg
1 | A |img3.jpg
答案 0 :(得分:3)
试试这个....(普通的mysql)
SELECT t1.*,t2.image FROM table1 t1
LEFT JOIN table2 t2 on t1.house_id=t2.house_id
WHERE t1.status= 1 GROUP BY t1.house_id ORDER BY house_id desc
活跃记录......
$this->db->select(t1.*,t2.image);
$this->db->from('table1'.' t1');
$this->db->join('table2'.' t2','t1.house_id=t2.house_id','left');
$this->db->where('t1.status',1);
$this->db->group_by("t1.house_id");
$this->db->order_by("house_id");