Consider the following table structure (not designed by me, and unchangable):
+---------------+-----------------------------+---------------------------+
| the_id | field_name | field_value |
+---------------+-----------------------------+---------------------------+
| 1 | county | lincolnshire |
| 1 | type | hotel |
| 2 | county | lincolnshire |
| 2 | type | castle |
+---------------+-----------------------------+---------------------------+
Basically, I want to perform a search on this data, returning the_id of anything that matches the parameters I specify. So, for example I want to search for all the_id fields which have (field_name = county AND field_value = lincolnshire) AND (field_value = type AND field_value = castle). Thus, only 1 would be returned.
Essentially, I want to know if it’s possible to perform a search on the returned results. Since the fields are completely separate entities linked by the_id, here’s what I’m thinking in pseudo-code:
- Look up
county - Search for
the_idandtypein the results - Return sub-set.
The problem is, I’m not 100% sure how this could be implemented in MySQL. Any feedback would certainly be gratefully received!
Ah, the joys of using an SQL database as key-value stores, because it makes the DB schema so much simpler… first off, take the original designer of this system out back and beat them up with a rotten wet fish, preferably whale-sized, dropped from a great height.
then…