Skip to content
Advertisement

How to store multiple values in a row, column or table? What is most efficient?

I have this problem where I want to create a data page where you can see how you’ve progressed in losing weight. I start by collecting their weight, but in order for me to actually do stuff with the data, I need multiple values.

For example – Below is a picture of my colums, where vaegtUsers and hoejdeUsers is the weight and height, however, I can’t really figure out how to store multiple weight values in one single column? Is there some way to get around this? I’ve done a bit of research and almost all say it’s not possible. Should I just add a new column for each “new” weight ID or keep creating tables for each individual user? Or should I do something completely else?

table

Advertisement

Answer

Since it appears a single user may have multiple weights at different times, you have a one to n relationships. You should create a second table (for instance, Measure) which refers to your User table.

This table could contain columns such as ID, UserId, MeasureDate, and weight.

You could also include height measure in this table if your users are not yet fully grown, and therefore susceptible to have varying height at different points in time. Otherwise, height could be stored inside user table.

On a side note, i would advise you to check database normalization for relational databases.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement