I use SQL-Server 2008 and have the following tables.
users
userid 1 2 3
objects
objectid | category 9 | A 8 | B 7 | A 6 | C
userobjects
userid | objectid 1 | 9 3 | 7 3 | 6
As you can see, userobjects is a link table. Unfortunately it is missing some entries. I could include them with a script but I wonder if there is a solution in sql.
For every userid and every objectid that belongs to category ‘A’ there should be an entry in userobjects. So what I wanted to have is this:
userid | objectid 1 | 9 1 | 7 2 | 9 2 | 7 3 | 9 3 | 7 3 | 6
This is a select query using
UNION(here is SQL-DEMO);