Red Stars Programming, food, and rambling

7Oct/090

Queryable Food Nutrition Database

The USDA releases data for food nutritional information. I've taken this data and loaded it into my local database, and created a front end to allow it to be queryable.

Database Schema

database schema

Sample Queries

Top 150 protein containing foods

SELECT Foods.Description, concat( NutrientValue, Units ) AS Value
FROM Foods
JOIN NutrientDefinitions ON ( NutrientName = 'Protein' )
JOIN NutrientData
USING ( NutrientID, FoodID )
ORDER BY NutrientValue DESC
LIMIT 150

Top 100 protein containing legumes

SELECT Foods.Description, concat( NutrientValue, Units ) AS Value
FROM FoodGroups
JOIN Foods
USING ( CategoryID )
JOIN NutrientDefinitions ON ( NutrientName = 'Protein' )
JOIN NutrientData
USING ( NutrientID, FoodID )
WHERE FoodGroups.Description like '%LEGUME%'
ORDER BY NutrientValue DESC
LIMIT 100

Top 150 iron containing foods

SELECT Foods.Description, concat( NutrientValue, Units ) AS Value
FROM Foods
JOIN NutrientDefinitions ON ( NutrientName like '%Iron%' )
JOIN NutrientData
USING ( NutrientID, FoodID )
ORDER BY NutrientValue DESC
LIMIT 150

Filed under: Web Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.