title: Query to update the corresponding parent_ids of table if child_ids are matching in table2 in SQL Server
body: <p>I have a table called level_1 and level_2.</p>
  
  <pre><code>Create table level_1
  (
       parent_id int,  
       child_id int, 
       status varchar(10)
  );
  
  Create table level_2
  (
       child_id int
  );
  </code></pre>
  
  <p>Level_1 table:</p>
  
  <pre><code>insert into level_1 
  values (11, 12, null), (12, 13, null), (13, 15, null),
         (17, 19, null), (22, 34, null), (23, 22, null),
         (29, 40, null), (40, 55, null), (32, 22, null),
         (19, 22, null), (55, 60, null)
  </code></pre>
  
  <p>Level_2 table:</p>
  
  <pre><code>insert into level_2 
  values(15), (22), (34), (60)
  
  select * from level_1;
  
   PARENT_ID   CHILD_ID STATUS
  ---------- ---------- ----------
          11         12
          12         13
          13         15
          17         19
          22         32
          19         22
          19         40
          40         19
          32         22
          19         22
          55         60
  </code></pre>
  
  <p>11 rows selected.</p>
  
  <pre><code>SQL&gt; select * from level_2;
  
    CHILD_ID
  ----------
          15
          19
          22
          60
  </code></pre>
  
  <p>Here I should update the status as 'Y' when level_2.child_id=level_1.child_id in Level_1 table and should update the corresponding parent_id values as 'Y' as shown below.</p>
  
  <pre><code>    -----------+----------+--------
      parent_id    child_id   status
      -----------+----------+--------
      11             12          Y
      12             13          Y
      13             15          Y
      23             22          Y
      17             19          Y
      19             22          Y
      22             34          Y
      29             40          Y
      40             55          Y
      55             60          Y
      -----------+----------+--------
  </code></pre>