简体   繁体   English

MySQL:Select 一个表中的多个值基于另一个表中的多个值

[英]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.

相关问题 根据另一个表中的值从一个表中选择多个值 - Select multiple values from one table based on values in another MySql - 如何根据在另一个表中加入的多个值从一个表中 select 行 - MySql - how to select rows from one table based on multiple values joined in another table mySQL:使用另一个表中的SELECT更新记录中的多个值 - mySQL: Updating multiple values in a record with a SELECT from another table Mysql, select 来自表多个值 - Mysql, select from table multiple values 根据MySQL中另一个表中的值从表中选择 - Select from table based on values in another table in MySQL 根据mySQL中另一个表的AVG值将多个记录插入表中 - Insert multiple records into a table based on AVG values from another table in mySQL MySQL根据当前表中的单元格从另一个表中获取多个值 - MySQL get multiple values from another table based on cells in current table 查询以基于此多个条件从表中选择值列表 - Query to select a list of values from a table based on this multiple criteria MySQL select 一个表中的值并根据第一个表中的值对另一个表中的值求和 - MySQL select a value from a table and sum values on another table based on the value from the first table 如何从mysql表中选择多个枚举值? - How to select multiple enum values from mysql table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM