I need query to provide distinct number of choices I have eight numbers in my database.
I need to return 28 distinct combinations.
I thought I had the code correct but it returns an infinite number of combinations.

Here is the code.

SELECT t1.ID AS Number_1, t2.ID AS Number_2, t3.ID AS Number_3
     , t4.ID AS Number_4, t5.ID AS Number_5, t6.ID AS Number_6 
FROM cTop8 AS t1, cTop8 as t2, cTop8 as t3, cTop8 as t4, cTop8 as t5, cTop8 as t6 
where t2.id&lt;&gt;t1.id and t3.id&lt;&gt;t2.id 
AND t3.id&lt;&gt;t1.id and t4.id&lt;&gt;t3.id 
AND t4.id&lt;&gt;t2.id AND t4.id&lt;&gt;t1.id 
and t5.id&lt;&gt;t4.id AND t5.id&lt;&gt;t3.id 
AND t5.id&lt;&gt;t2.id AND t5.id&lt;&gt;t1.id 
and t6.id&lt;&gt;t5.id AND t6.id&lt;&gt;t4.id 
AND t6.id&lt;&gt;t3.id AND t6.id&lt;&gt;t2.id 
AND t6.id&lt;&gt;t1.id ORDER BY rand()
If by distinct combinations you mean distinct sets of numbers, regardless of their order (in fact, sets are unordered, according to the algebra of sets), then the only fix your script requires is to replace each &lt;&gt; with either &gt; or &lt;, by which I mean that it should be either all &lt; or all &gt;.

After you switch the comparison symbol, some comparisons will become redundant, and so your query can be simplified. Here is one way to rewrite it:

SELECT
  t1.ID AS Number_1,
  t2.ID AS Number_2,
  t3.ID AS Number_3,
  t4.ID AS Number_4,
  t5.ID AS Number_5,
  t6.ID AS Number_6
FROM
  cTop8 AS t1,
  cTop8 AS t2,
  cTop8 AS t3,
  cTop8 AS t4,
  cTop8 AS t5,
  cTop8 AS t6
WHERE t1.ID &lt; t2.ID
  AND t2.ID &lt; t3.ID
  AND t3.ID &lt; t4.ID
  AND t4.ID &lt; t5.ID
  AND t5.ID &lt; t6.ID
;


And the output would be exactly 28 rows:

Number_1  Number_2  Number_3  Number_4  Number_5  Number_6
--------  --------  --------  --------  --------  --------
1         2         3         4         5         6
1         2         3         4         5         7
1         2         3         4         5         8
1         2         3         4         6         7
1         2         3         4         6         8
1         2         3         4         7         8
1         2         3         5         6         7
1         2         3         5         6         8
1         2         3         5         7         8
1         2         3         6         7         8
1         2         4         5         6         7
1         2         4         5         6         8
1         2         4         5         7         8
1         2         4         6         7         8
1         2         5         6         7         8
1         3         4         5         6         7
1         3         4         5         6         8
1         3         4         5         7         8
1         3         4         6         7         8
1         3         5         6         7         8
1         4         5         6         7         8
2         3         4         5         6         7
2         3         4         5         6         8
2         3         4         5         7         8
2         3         4         6         7         8
2         3         5         6         7         8
2         4         5         6         7         8
3         4         5         6         7         8


Feel free to keep your ORDER BY RAND() if the row order needs to be randomised.