Jump to content


Photo

Finding duplicates database entries


  • Please log in to reply
7 replies to this topic

#1 majocmatt

majocmatt
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 06 September 2006 - 09:18 PM

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.

#2 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 06 September 2006 - 09:35 PM

SQL DISTINCT might help you
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#3 majocmatt

majocmatt
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 06 September 2006 - 09:59 PM

but I dont neccessarily know what I will be searching for.

distinct would eliminate duplicates, no?

#4 MarioRossi

MarioRossi
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 September 2006 - 10:32 PM

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.


#5 majocmatt

majocmatt
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 06 September 2006 - 11:17 PM

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.

#6 MarioRossi

MarioRossi
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 September 2006 - 11:36 PM

OK

try this;

SELECT COUNT(DISTINCT vote) AS votecount, vote 
FROM UsersTable GROUP BY vote

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 07 September 2006 - 12:45 AM

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 majocmatt

majocmatt
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 07 September 2006 - 02:09 AM

cool thanks, i got it

thank you all for the valuable input, its much appreciated.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users