Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
HAVING COUNT(*) > 1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading