1

I have a data storage requirement where each item has several fields and each field may contain more than one value (strings). And I need to run a Search query where item(s) will be selected based on one or more of the field values. here is structure what I need :

Name:     (this will be the name of an item)
Season:   (name of the season)
Taste:    (1 taste or several)
Funktion: (1 or several option)
Weight:   (1 or several)
Volume:   (1 volume or several)
Tips:     (for comments)
Flavor combinations: (1 or several)
Matching flavors: (several)

Please any suggestions regarding both the database design search queries for MySql.

2 Answers 2

2

A simple "one-to-many" should work:

enter image description here

You search by JOINing ITEM with each of the "child" tables.


If you wish to limit the attribute values, you can do a "real" many-to-many:

enter image description here

So, an item cannot be associated with a taste that is not already in the TASTE table (etc. for other kinds of attributes).


Or you could even make a generalized model, so you are not limited to any particular set of attributes:

enter image description here

Caveat: this is very flexible and you now need to JOIN with just one table, but consistency is harder to enforce and may be necessary to do at the application level.

Sign up to request clarification or add additional context in comments.

Comments

0

The standard design for multi valued attributes is a many-to-many table - this would normally consist of a compound primary key consisting of two foreign keys - one for each of the join tables.

The query on these would involve this many-to-many table.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.