I am trying to create a query in SQL Server that will look for all combinations of numbers in a table.
COMBINATION TABLE
CombID Comb_Num1 Comb_NumTwo Comb_NumThree 1 1 2 3 2 2 10 15 3 5 20 60 4 10 22 50 5 22 33 46
Numbers range from 1-60, and the same number is not repeated in combination. The order does not matter.
ENTRANCE TABLES
EntryID NumberOne NumberTwo NumberThree NumberFour NumberFive 1 10 22 33 46 50 2 2 10 15 22 40 3 24 33 40 45 50 4 5 10 22 40 60 5 2 6 10 22 40 6 2 10 22 50 60 7 10 22 33 46 50
Numbers range from 1-60, and the same number is not repeated in the record. The order does not matter.
results
- Searching for combination 1 will not produce results
- Search for combination 2 returns EntryID 2
- Searching for combination 3 will not produce results
- Searching for combination 4 will return EntryID 1, 6, 7
- Searching for combination 5 returns EntryID 1, 7
The query should also show each entry in the combination table, how many times it has appeared in the Entry table. It should exclude combinations that are not displayed in the input table.
source share