sorting - creating groups from related pairs -


i have list of parts in mssql db a=b, a=c, a=d want arrange in groups since b=c, b=d etc. way in database, search matches "d" , result a, b , c match. i'm using mssql. how go creating new table , inserting data a, b, c, , d in group 1, , if x=y, x=z x, y, z in group 2 , on?

╔═════════╦═══════╦═══════╗ ║ matchid ║ part1 ║ part2 ║ ╠═════════╬═══════╬═══════╣ ║       1 ║     ║ b     ║ ║       2 ║     ║ c     ║ ║       3 ║     ║ d     ║ ║       4 ║ x     ║ y     ║ ║       5 ║ x     ║ z     ║ ╚═════════╩═══════╩═══════╝ 

to

╔═════════╦═══════╦═══════╦═════════╗ ║ matchid ║ part1 ║ part2 ║ groupid ║ ╠═════════╬═══════╬═══════╬═════════╣ ║       1 ║     ║ b     ║       1 ║ ║       2 ║     ║ c     ║       1 ║ ║       3 ║     ║ d     ║       1 ║ ║       4 ║ x     ║ y     ║       2 ║ ║       5 ║ x     ║ z     ║       2 ║ ╚═════════╩═══════╩═══════╩═════════╝ 

the idea list parts without needing know possible combinations no matter 1 i'm looking for, if there's query might work on original format of data, maybe better


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -