I am stuck on a nested database query. Can I get some help?
My simple table looks like this:
food_table:
+----+----------+-------------------------------+
| ID | NAME | Nutrient | NutrientAmount
+----+----------+---------------+---------------+
food1 calcium 200
food1 magnesium 300
food1 phosphorus 400
food2 calcium 220
food2 magnesium 320
food2 phosphorus 430
food3 calcium 230
.............
I want to select top 15 foods that have the most calcium and magnesium. It doesn't matter calcium or magnesium has the most.
I tried to use order by, but it doesn't work because it is to order a column. The data that I want to sort is stored in different rows.
I am new to database design. If schema has problem, I am am to change the schema also.