sql server - Trouble with logic on how to query for all possible 5 number combinations of numbers 1 - 69 into SQL table -


edit: clarify, order of results matters in 1,2,3,4,5 , 5,4,3,2,1 should same record. i'm looking distinct combinations.

i'm looking build sql database possible 5 number combinations of numbers 1 - 69 same number cannot used twice in single 5 number combination. result contain 11,238,513 records. i'm having trouble writing code work correctly logic @ play. i've attempted crazy macro in excel vba feel sql have simpler , quicker. i've asked similar doesn't me there (how create list of 5 number permutations based on list of numbers ranging 1-69?).

i've tried variations of below, can't seem conceptualize how should attacking this. help?

with range ( select num1 c test1   union     select num2 test1   union     select num3 test1   union     select num4 test1   union     select num5 test1) select * range r1,range r2,range r3,range r4,range r5 r1.c <> r2.c , r1.c<>r3.c , r1.c<>r4.c , r1.c<>r5.c , r2.c <> r3.c , r2.c<>r4.c , r2.c<>r5.c , r3.c<>r4.c , r3.c<>r5.c , r4.c <> r5.c order r1.c, r2.c, r3.c, r4.c, r5.c 

cartesian product table 5 times, , choose rows numbers in increasing order (this ensures same number isn't selected more once, , there no permutations of same 5 numbers):

select r1.c, r2.c, r3.c, r4.c, r5.c range r1, range r2, range r3, range r4, range r5 r1.c<r2.c , r2.c<r3.c , r3.c<r4.c , r4.c<r5.c 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -