0

50 Users with a record format

  • Id,
  • Name,
  • Group_Id

And Groups

1,
2,
3

Are to be inserted into a pairs table in the format

  • Id,
  • Pair_1,
  • Pair_2

Note

Users belongs to different groups.

Users from group 2 cannot pair with each other and users from group 3 can also not pair with each other, duplicates must also be avoided.

How do i go about this in Sql. Am a novice.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Sample data and desired results would really help, as would an appropriate database tag. You have columns called `pair_1` and `pair_2` but you explain nowhere what these are. – Gordon Linoff Feb 16 '20 at 04:04

1 Answers1

0

This is a sample data in Javascript [ { Id:1, Name:"James", Group_Id:3 }, { Id:2, Name:"Daniel", Group_Id:3 }, { Id:3, Name:"Jonathan", Group_Id:2 }, { Id:4, Name:"Esther", Group_Id:1 }, { Id:5, Name:"Leo", Group_Id:1 } ]

Pair_1 & Pair_2 are two paired users to be added to a pairs table based on the condition explained earlier.