title: How to match/compare values in two resultsets in SQL Server 2008?
body: <p>I'm working on a employee booking application. I've got two different entities Projects and Users that are both assigned a variable number of Skills. </p>
  
  <p>I've got a Skills table with the various skills (columns: id, name)
  I register the user skills in a table called UserSkills (with two foreign key columns: fk_user and fk_skill)
  I register the project skills in another table called ProjectSkills (with two foreign key columns: fk_project and fk_skill).</p>
  
  <p>A project can require maybe 6 different skills and users when registering sets up their Skills aswell.</p>
  
  <p>The tricky part is when I have to find users for my Projects based on their skills. I'm only interested in users that meet that have ALL the skills required by the project. Users are ofcause allowed to have more skilled then required.</p>
  
  <p>The following code will not work, (and even if it did, would not be very performance friendly), but it illustrates my idea:</p>
  
  <pre><code>SELECT * FROM Users u WHERE 
      ( SELECT us.fk_skill FROM UserSkills us WHERE us.fk_user = u.id ) 
          &gt;= 
      ( SELECT ps.fk_skill FROM ProjectSkills ps WHERE ps.fk_project = [some_id] )
  </code></pre>
  
  <p>I'm thinking about making my own function that takes two TABLE-variables, and then working out the comparisson in that (kind of a modified IN-function), but I'd rather find a solution that's more performance friendly. </p>
  
  <p>I'm developing on SQL Server 2008.</p>
  
  <p>I really appreciate any ideas or suggestions on this. Thanks!</p>