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.
| 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 VOTERMKRVM 2782885999MKRVF 2782885999MKCTM 2782885999Left(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 fieldsMy 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. ThanksJames |
|
|
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 YourTableGROUP BY VoterTara Kizerhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
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" |
 |
|
|
|
|
|