majocmatt Posted September 6, 2006 Share Posted September 6, 2006 This might not belong here but most of you all work with mysql too...I have a voting system where people type their vote in a textbox, not from a radio group. This is because there can be so many answers. I'm currently creating a spellcheck script that will eliminate wrongly typed names, or at least try. My problem is however, tallying up the votes.DB Schema (id,vote,ip,date) - the vote field will be a name of a person.Let's say there are three entries of the name Naked Cowboy in the database, and lets say he has the most votes. How would my query find that he is indeed the most voted on. In other words, how does one construct a query to tally up duplicates of the name field?Thanks. Quote Link to comment Share on other sites More sharing options...
AdRock Posted September 6, 2006 Share Posted September 6, 2006 SQL DISTINCT might help you Quote Link to comment Share on other sites More sharing options...
majocmatt Posted September 6, 2006 Author Share Posted September 6, 2006 but I dont neccessarily know what I will be searching for.distinct would eliminate duplicates, no? Quote Link to comment Share on other sites More sharing options...
MarioRossi Posted September 6, 2006 Share Posted September 6, 2006 Why not put a users table in you db with 3 columns (id, Name, Votes)?You could then use a dropdown box to list the names and increment the votes column on each vote. Quote Link to comment Share on other sites More sharing options...
majocmatt Posted September 6, 2006 Author Share Posted September 6, 2006 Thats the thing, its a public voting system, and I dont want a constrained list of vote possibilities, users will be able to choose any name they like. Quote Link to comment Share on other sites More sharing options...
MarioRossi Posted September 6, 2006 Share Posted September 6, 2006 OKtry this;SELECT COUNT(DISTINCT vote) AS votecount, vote FROM UsersTable GROUP BY vote Quote Link to comment Share on other sites More sharing options...
Barand Posted September 7, 2006 Share Posted September 7, 2006 COUNT(DISTINCT vote) ... GROUP BY voteshould always give a count of 1 !TrySELECT COUNT(*) AS votecount, vote FROM UsersTable GROUP BY voteHAVING votecount > 1 Quote Link to comment Share on other sites More sharing options...
majocmatt Posted September 7, 2006 Author Share Posted September 7, 2006 cool thanks, i got itthank you all for the valuable input, its much appreciated. 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.