mercredi 25 février 2015

SQL Distinct Random select


Hi can anyone help with this little MS SQL Puzzle.


I basically need to get a 1 random answer from each of the submitters.



id, submitter, answer

1, James, Blue

2, James, Red

3, James, Orange

4, Ian, Yellow

5, Ian, Pink

6, Robert, Red


I have tried the following but obviously this will always get the min(id) or Max(id) what I need is a random(id)?



select * from #tmpData
where id in (
select min(id ) FROM #tmpData
group by submitter
)


Thanks in advance..





Aucun commentaire:

Enregistrer un commentaire