[英]MySQL: Select multiple values from a table based on multiple values from another table
I would like to return all the reports that are about each of these regions, that belong to a macroregion...我想返回所有关于这些区域的所有报告,属于一个宏观区域......
I would like to somehow我想以某种方式
SELECT DISTINCT report FROM reports WHERE region =
(SELECT distinct region from macroregions where macroregion = 'Africa')
The regions in the macroregion are Sahara, West Africa, Tropical Africa,... etc宏观区域的区域是撒哈拉沙漠、西非、热带非洲等
Although this is impossible since it the subquery would return multiple results.尽管这是不可能的,因为子查询将返回多个结果。
SELECT DISTINCT report FROM reports WHERE
region IN
(SELECT distinct region from macroregions where macroregion = 'Africa')
Maybe you missed IN
operator也许你错过了
IN
运算符
This should get you what you need:这应该可以满足您的需求:
SELECT
r.report
FROM
reports r
INNER JOIN
macroregions m ON
m.region = r.region
AND
m.macroregion = 'Africa'
This is all of the reports associated to regions associated to the macroregion 'Africa'.这是与宏观区域“非洲”相关的区域的所有报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.