我有一个查询要加入3个表。
user_driver
我希望显示vendor_location
表的其余部分,即使{for LocationName
表没有匹配的值。 NULL
字段可以填充left outer
,而不是根本不显示任何内容。
我尝试了full outer
和@Override
public long getItemId(int position) {
Object obj = getItemAtPosition(position);
return obj.hashCode();
}
,但它无效。它让我只有一行显示。
答案 0 :(得分:1)
我想展示user_driver表的其余部分,即使没有与vendor_location表匹配的值。
为此,您应该使用LEFT JOIN。它允许您从左侧的表中获取行,即使右表中没有匹配项。
$this->db->select("a.user_id as id, a.plate_number as plate_number, a.current_lat as lat, a.current_lon as lon, a.created_on as created_on, a.updated_on as updated_on, a.available as available, a.location_id as location_id, b.user_name as name, b.user_email as email, b.user_phone as phone, c.name as location_name");
$this->db->from('user_driver as a');
$this->db->join('user as b', 'a.user_id = b.user_id');
$this->db->join('vendor_location as c', 'a.location_id = c.location_id', 'left');//modify this line
$query = $this->db->get();
$data['driver'] = $query->result_array();
答案 1 :(得分:0)
$this->db->join('user as b', 'a.user_id = b.user_id', 'LEFT');
$this->db->join('vendor_location as c', 'a.location_id = c.location_id', 'LEFT');