首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不同的MySQL连接

不同的MySQL连接
EN

Stack Overflow用户
提问于 2018-03-09 15:39:45
回答 1查看 61关注 0票数 1

希望有人能帮我做一个MYSQL查询

我有三个数据库表:

  • points_of_interest
  • point_of_interest_type
  • poi_poi_types

points_of_interest表包含有关某个区域的所有详细信息。

point_of_interest_type表是一个类型列表,例如餐厅、咖啡厅、博物馆等。这个表还有一个活动列(1或0)。

poi_poi_types是一个映射表,因此它包含感兴趣点的id和感兴趣点类型的id。

一个感兴趣的点可以有许多兴趣点类型,因此有可能在poi_poi_types表中有多个条目

因此,我想要的结果是返回一个points_of_interest列表,但只返回活动的兴趣点类型

这是我到目前为止的代码点火器查询,但它不正确-它正在返回poi_poi_types表中的实际感兴趣点的每一秒。

代码语言:javascript
运行
复制
    $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);
EN

回答 1

Stack Overflow用户

发布于 2018-03-09 20:13:34

我认为这是可行的。好的,将其设置为使select语句变得不同。我认为这实际上会对SELECT DISTINCT产生影响

代码语言:javascript
运行
复制
$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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49197245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档