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? Link to comment https://forums.phpfreaks.com/topic/82446-solved-setting-a-field-equal-to-a-count-in-mysql/ 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. Link to comment https://forums.phpfreaks.com/topic/82446-solved-setting-a-field-equal-to-a-count-in-mysql/#findComment-419185 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. Link to comment https://forums.phpfreaks.com/topic/82446-solved-setting-a-field-equal-to-a-count-in-mysql/#findComment-419187 Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 No probs Link to comment https://forums.phpfreaks.com/topic/82446-solved-setting-a-field-equal-to-a-count-in-mysql/#findComment-419197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.