Jump to content

Archived

This topic is now archived and is closed to further replies.

majocmatt

Finding duplicates database entries

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
COUNT(DISTINCT vote) ... GROUP BY vote

should always give a count of 1 !

Try

SELECT COUNT(*) AS votecount, vote
FROM UsersTable GROUP BY vote
HAVING votecount > 1

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.