How to query to see if a set of numbers have been duplicated before in sql server on the same table?

So, due to the huge Powerball $2.3billion jackpot, I was wondering how does one query a lottery database where there are columns num1, num2, num3, num4, num5, num6 for a certain draw date and compare that to past winning numbers on itself to see if there are duplicate sets? (ie. if the winning numbers have ever repeated itself)?

couldn’t think of how to query – i am a newbie in sql

>Solution :

Assuming the schema was as described, you could simply GROUP BY all six columns to see if the numbers had repeated. This would work for the jackpot, smaller prizes would require additional work.

SELECT num1, num2, num3, num4, num5, num6, COUNT(*) AS Frequency
FROM LotteryTable
GROUP BY num1, num2, num3, num4, num5, num6

Leave a Reply