I'm creating a simple web forum and have decided to keep a count of all replies to a thread in a column in the threads table to avoid joining accross to the replies table every time. The problem I'm having is in updating the threads table. I cannot seem to increment the reply_count in one query. I have tried the following.
//Idealy what I want to do
UPDATE threads SET reply_count=reply_count+1 WHERE thread_id=$thread_id;
//Doesn't work and doesn't really address the issue very well anyway. I'm trying to speed things up by cuttong out a query, this just sticks them both together.
UPDATE threads SET reply_count=(SELECT reply_count FROM threads WHERE thread_id=$thread_id)+1 WHERE thread_id=$thread_id;
Thanks in advance
Answers on a postcard
Bubble