Hello, I am building a database to store votes. Is it possible to make a database field increase each time something is submitted/inserted into it to keep track of how many votes that item is getting?
Thanks! Jon
UPDATE tbl (fld=fld+1);
Jon7800 wrote:Is it possible to make a database field increase each time something is submitted/inserted into it to keep track of how many votes that item is getting?
Is it possible to make a database field increase each time something is submitted/inserted into it to keep track of how many votes that item is getting?
why hardcode it? why not do a simple COUNT() query?
With a trigger, yes it's quite easy. But since you're probably not using a version of MySQL that supports triggers, you'll be doing it yourself. also pretty easy. Only works with update, not insert, of course.
Yeah, I store votes and use a trigger to update the count and average fields (using pgsql). Back when I used mysql I had to try using aggregates - they very quickly ran into performance problems.