I have a datebase with geo-based content. A field 'geo' determines what countries a certain row is for (could be multiple). I want to have every country code from MySQL for which there should be a different result. If there's no content in the DB specifically for "CN" for instance we can use the 'general' result for rows that are not specifically for a certain country.
id | geo |
---+--------+
1 | NL |
2 | US |
3 | |
4 | CA NL |
5 | US |
What I want to get back is:
| geo |
+-----+
| |
| NL |
| US |
| CA |
I tried playing with CONCAT (SELECT GROUP_CONCAT from db) to get all possible entries found in the database, but that would involve splitting two results (for ID#4) in two rows in order to get something like "NL,US,CA" back, that would already help.
A solution would be to generate a MANY-TO-MANY database for this, which would make it very easy to select the countries used in the table. Another way could be to get everything GROUPED by GEO and use PHP to determine what countries to use, but I can't stop thinking there must be a cleaner way to solve this query in MySQL. Another possible approach is discussed in this SO post, but that's just ONE possible approach for this problem (and thus no reason to close this question as 'duplicate' since it clearly isn't...)
Does anybody know what route to take?