Skip to main content
Notice removed Improve details by Ankit
Bounty Ended with Hamlet Hakobyan's answer chosen by Ankit
Notice added Improve details by Ankit
Bounty Started worth 50 reputation by Ankit
added 13 characters in body; edited title
Source Link
marc_s
  • 759.6k
  • 185
  • 1.4k
  • 1.5k

Recursive Queryquery in sql serverSQL Server

I have a table with following structure

Table name: matchesmatches

Table name: matches

That basically stores which product is matching which product. I need to process this table And store in a groups table like below.

Table Name: groupsgroups

enter image description here

group_IDgroup_ID stores the MIN Product_IDMIN Product_ID of the Product_IDSProduct_IDS that form a group. To give an example let's say If

If A is matching B and B is Matching C then three recordsrows should go to group table in format (A, A), (A, B), (A, C)(A, A), (A, B), (A, C)

I have tried looking into Coco-related subqueries and CTE, but not getting this to implement. 

I need to do this all in SQL.

Thanks for the help .

Recursive Query in sql server

I have a table with following structure

Table name: matches

Table name: matches

That basically stores which product is matching which product. I need to process this table And store in a groups table like below.

Table Name: groups

enter image description here

group_ID stores the MIN Product_ID of the Product_IDS that form a group. To give an example let's say If A is matching B and B is Matching C then three records should go to group table in format (A, A), (A, B), (A, C)

I have tried looking into Co-related subqueries and CTE, but not getting this to implement. I need to do this all in SQL.

Thanks for the help .

Recursive query in SQL Server

I have a table with following structure

Table name: matches

Table name: matches

That basically stores which product is matching which product. I need to process this table And store in a groups table like below.

Table Name: groups

enter image description here

group_ID stores the MIN Product_ID of the Product_IDS that form a group. To give an example let's say

If A is matching B and B is Matching C then three rows should go to group table in format (A, A), (A, B), (A, C)

I have tried looking into co-related subqueries and CTE, but not getting this to implement. 

I need to do this all in SQL.

Thanks for the help .

Source Link
Ankit
  • 1.9k
  • 2
  • 21
  • 41

Recursive Query in sql server

I have a table with following structure

Table name: matches

Table name: matches

That basically stores which product is matching which product. I need to process this table And store in a groups table like below.

Table Name: groups

enter image description here

group_ID stores the MIN Product_ID of the Product_IDS that form a group. To give an example let's say If A is matching B and B is Matching C then three records should go to group table in format (A, A), (A, B), (A, C)

I have tried looking into Co-related subqueries and CTE, but not getting this to implement. I need to do this all in SQL.

Thanks for the help .