mysql查询引用三个表

标签 mysql sql

我有三个表,分别是目的地、位置和意图。 他们彼此之间存在以下关系。我正在尝试获取给定意图的位置及其相应的目的地。 但我目前无法做到这一点。 有什么想法吗?

database schema

例如:获取“徒步旅行”意图的位置名称及其对应的目的地

查询失败:

select destination.name,location.name from location,destination,intention where
intention.name='hiking' AND location.destination_id=destination.destination_id AND
intention.intention_id=location.intention_id 

Example location data

Example destination data

Example intention data

最佳答案

位置表中不存在徒步旅行的intent_id 1,因此没有返回行

关于mysql查询引用三个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46996436/

相关文章:

Mysql从集合中删除特殊字符

mysql - MySQL查询剥离

php - 两个词之间的空格和链接问题

sql - 使用 Postgres 聚合函数选择每个 GROUP BY 组中的第一行?

mysql - 忠诚度计划数据库设计

MySql排序工作异常

php - 优化 MySQL 搜索过程

java - 在 IBM Maximo 中使用 SQL 语句,使用 Java

c# - 我仍然可以使用 CAML 进行此查询吗?

java - 具有规范和分页支持的 Spring 数据分组