title: In SQL Server, how to SELECT rows that share a common column value?
body: <p>In my table I have the following values:</p>
  
  <pre><code>ProductId  Type      Value      Group
  200        Model     Chevy      Chevy
  200        Year      1985       Chevy
  200        Year      1986       Chevy
  200        Model     Ford       Ford
  200        Year      1986       Ford
  200        Year      1987       Ford
  200        Year      1988       Ford
  </code></pre>
  
  <p>In my query, I wanna know if my product is compatible to a certain model in a given year. I'm trying to build a function that returns true or false, depending on the parameters ProductId, Model and Value I pass to it. To be true, the Function have to match both parameters (Model and Year), along with the ProductId in the table, but they must belong to the same group.</p>
  
  <p>For example, if I pass to the function the values 200, Chevy, 1988 it must return False. Notice that the 3 values are found in the table, but they belong to different groups.</p>
  
  <p>On the other hand, if I pass to the function the values 200, Ford, 1986 it must return True, because all 3 values match and belong to the same group.</p>
  
  <p>I think a way of doing that is in multiple steps, like:</p>
  
  <ol>
  <li>Select all records that match the model then all that match the year and insert them into a temporary table;</li>
  <li>Select distinct the groups to another temp table;</li>
  <li>Loop through each group checking if I find all the matches in that group, returning true when I found or false at the end of the function.</li>
  </ol>
  
  <p>I wonder if there's a better way of doing this in 1 step using only one SELECT command.</p>