Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SMS VOTING SYSTEM

Author  Topic 

jmuritu
Starting Member

1 Post

Posted - 2007-07-26 : 01:07:38
Hi all,

I've the following records in a table:
CANDIDATE VOTER
MKRVM 2782885999
MKRVF 2782885999
MKCTM 2782885999

Left(candidate,2) represents a candidate whilst voter represents a voter who voted for the candidate via sms. substring(CANDIDATE,3,2) represents a state whilst substring(CANDIDATE,5,1) represents Male or Female. Candidate and Voter are separate fields

My problem is this: Voter(+2782885999) has voted three times and I would want to retain only one vote from him. A select distinct won't work. How do I retain only one vote from this guy.

Thanks

James

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-07-26 : 01:11:28
You can use a GROUP BY with either MIN or MAX on whichever field will determine which vote to keep.

SELECT Voter, MAX(SomeColumn) -- or MIN(SomeColumn)
FROM YourTable
GROUP BY Voter

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-26 : 05:28:16
Do you have some kind of identity, or a datetime when vote was made?
Do you want to keep the first vote, or the last vote?



E 12°55'05.76"
N 56°04'39.42"
Go to Top of Page
   

- Advertisement -