希望有人能帮我做一个MYSQL查询
我有三个数据库表:
points_of_interest表包含有关某个区域的所有详细信息。
point_of_interest_type表是一个类型列表,例如餐厅、咖啡厅、博物馆等。这个表还有一个活动列(1或0)。
poi_poi_types是一个映射表,因此它包含感兴趣点的id和感兴趣点类型的id。
一个感兴趣的点可以有许多兴趣点类型,因此有可能在poi_poi_types表中有多个条目
因此,我想要的结果是返回一个points_of_interest列表,但只返回活动的兴趣点类型
这是我到目前为止的代码点火器查询,但它不正确-它正在返回poi_poi_types表中的实际感兴趣点的每一秒。
$this->db->select('poi.*, poi_types.type as poi_type');
$this->db->from('poi');
$this->db->join('poi_poi_types', 'poi.id = poi_poi_types.poi_id');
$this->db->join('poi_types', 'poi_types.id = poi_poi_types.poi_type_id');
$this->db->where('poi_types.active', 1);发布于 2018-03-09 20:13:34
我认为这是可行的。好的,将其设置为使select语句变得不同。我认为这实际上会对SELECT DISTINCT产生影响
$this->db->distinct();
$this->db->select('poi.*, poi_types.type as poi_type');
$this->db->from('poi');
$this->db->join('poi_poi_types', 'poi.id = poi_poi_types.poi_id');
$this->db->join('poi_types', 'poi_types.id = poi_poi_types.poi_type_id');
$this->db->where('poi_types.active', 1);https://stackoverflow.com/questions/49197245
复制相似问题