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 = 开发者_JAVA百科'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
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'.
精彩评论