tibberous Posted December 20, 2007 Share Posted December 20, 2007 I have two tables, games and categories. Each game have a category field, which holds the id of the category it belongs to. Each category keeps track of how many games are in it, and records it in the gamecount field. Is there a way to set categorie's gamecount field to the number of games with a certain category, all in a single query? select count(*) from games where category=1 returns a 4. And... update categories set gamecount='4' where id='1' But update categories set gamecount='(select count(*) from games where category=1)' where id='1' Doesn't do anything. Anyone know why? Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 Did you try removing the ' ' around your sql query? It looks to me like you're just setting it to that string, instead of the result of that query. Quote Link to comment Share on other sites More sharing options...
tibberous Posted December 20, 2007 Author Share Posted December 20, 2007 !!! Damn it! Thats it... I thought I was missing something fundamental with subqueries, here it was just something stupid. Thanks a ton. Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 No probs Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.