CREATE VIEW avgrating SELECT itemid, AVG( rating ) AS the_avg FROM ratinglist WHERE catagory = ? GROUP BY itemid ORDER BY AVG( rating ); SELECT itemlist.itemid, the_avg, foo FROM itemlist, avgrating WHERE itemlist.itemid = avgrating.itemid;