I have a table that looks like this:
target_id || country_code
5———–||——-US—-
5———–||——-CA—
2———-||——-FR—-
3———-||——-SP—-
3———-||——-FR—-
And another table that looks like this:
target_id || region_name
5———–||—North America
2———–||—–France——
3———–||—–Some Europe
As you can see, table 2 contains locations and target_ids, while table 1 contains where these locations are targeted. In the case of North America, it is targeted to 5, which belongs to Canada and US. France, on the other hand has a target_id of 2, and Some Europe a target_id of 3, which contains France again and Spain.
What I would like to do via MySQL, is to get a table of target_id, country_code, country_name but only for countries. This means, only to the target_ids of table 1 that are in only one row (for example, we know that FR is a country because number 2 is only in FR, and we know that 3 represents a region because it has both Spain and France associated). Is this possible to do via MySQL or will I need two queries and PHP in the middle?
Thanks!
table1is the one with the country codes,table2is the one with the the region names.