I have the following set up:
[clients]: id
(ai), name
(text), regions
(text);
[regions]: id
(ai - related to region_id
in [municipalities]), name
(text);
[municipalities]: id
(ai - related to municipality_id
in [postals]), name (text), region_id
(int);
[postals]: id
(ai), name
(text), municipality_id
(int).
- all the id's are primary keys
The regions
column in [clients] contains a string like "1", "1,2" or "1,3,7".
Now, the general idea is the someone enters a specific value for postal name, and the client name is returned when the postal code falls into the specific region. Each municipality belongs to a specific region and each postal code belongs to a specific municipality. A client can work within multiple regions.
I have the following query:
select name from clients where find_in_set((select region_id from municipalities where id = (select municipality_id from postals where name = "string")),(select regions from clients)) != 0
But I keep getting #1242 - Subquery returns more than 1 row, and I don't know why. The searched string should only return 1 municipality_id, which in turn should only return 1 region_id, which should only be found once in the regions
string in the [clients] table.
What am I missing here?