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. Link to comment https://forums.phpfreaks.com/topic/19948-finding-duplicates-database-entries/ Share on other sites More sharing options...
AdRock Posted September 6, 2006 Share Posted September 6, 2006 SQL DISTINCT might help you Link to comment https://forums.phpfreaks.com/topic/19948-finding-duplicates-database-entries/#findComment-87415 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? Link to comment https://forums.phpfreaks.com/topic/19948-finding-duplicates-database-entries/#findComment-87421 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. Link to comment https://forums.phpfreaks.com/topic/19948-finding-duplicates-database-entries/#findComment-87435 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. Link to comment https://forums.phpfreaks.com/topic/19948-finding-duplicates-database-entries/#findComment-87461 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 Link to comment https://forums.phpfreaks.com/topic/19948-finding-duplicates-database-entries/#findComment-87469 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 Link to comment https://forums.phpfreaks.com/topic/19948-finding-duplicates-database-entries/#findComment-87502 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. Link to comment https://forums.phpfreaks.com/topic/19948-finding-duplicates-database-entries/#findComment-87543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.