title: SQL query to filter column based on other columns
body: <p>I have a relational table that looks something like below:</p>
  
  <p>I want to write a query to which if i give a input of tag_id i need to get the video_id based on the following rule.
  If the tags belong to the same category then OR condition between tags.
  If tags belong to different category then AND condition between the tags</p>
  
  <pre><code>tag_id  pvid_id     cat_id  
  1       1           1   
  1       2           1   
  2       2           2
  </code></pre>
  
  <p>In the above example,</p>
  
  <p>If i give tag_id 1 as the input, the expected output of pvid_id as 1,2</p>
  
  <p>If i give tag_id 1,2 as the input, the expected output of pvid_id is 2</p>
  
  <p>I am unable to fromulate the query, can someone please help me with it or give me a direction towards getting the solution?</p>
  
  <p>Thanks</p>