Suppose I have records:
======= =========
Element id
======= =========
"H"
"O"
And another like:
======== ==
Compound id
======== ==
"Water"
With:
======== == =========== ========== ==========
Relation id compound_id element_id bond
======== == =========== ========== ==========
1 "Water" "H" "Covalent"
2 "Water" "H" "Covalent"
3 "Water" "O" "Covalent"
Now, most of my queries aren't for an exact match, but suppose sometimes I want to find the compound with the exact elements = ["H", "H", "O"]
(i.e. Water -- but not Hydroxide (["H", "O"]
) or Peroxide (["H", "H", "O", "O"]
).
How might I go about this?
- Consensus seems to have it, that the best way to store arrays in SQL is through many-to-many intermediate tables.
- However, querying for an exact match without arrays seems slow and complex, even with database-specific functions like
GROUP_CONCAT
.