title: Comparing two tables using sub query ?
body: <p>I  can compare two tables for missing data using the below query </p>
  
  <pre><code> SELECT S.DEVID,S.INPUTID,S.PRI,S.CCID FROM [DEVICE-SECURITY].DBO.DEVICE_LINK S
    WHERE HID = 4 
    EXCEPT 
    SELECT  T.DEVID,T.INPUTID,T.PRI,T.CCID  FROM  DEVICE-CONFIG.DBO.DEVICE_LINK T
    WHERE HID = 1 
  </code></pre>
  
  <blockquote>
    <p>The above query returns four rows which are not present in my source
    table</p>
  </blockquote>
  
  <p>Now  i am trying to use a subquery to achieve the same result  </p>
  
  <pre><code> SELECT  S.DEVID,S.INPUTID,S.PRI,S.CCID , 
   CASE WHEN S.HID = '4' THEN '1'  END AS HID 
   FROM  [DEVICE-SECURITY].DBO.DEVICE_LINK S
    WHERE S.HID= 4 AND  NOT EXISTS    (
   SELECT T.DEVID,T.INPUTID,T.PRI,T.CCID FROM DEVICE-CONFIG.DBO.DEVICE_LINK  T
     WHERE T.HID = 1 )
  </code></pre>
  
  <blockquote>
    <p>It returns no rows .</p>
  </blockquote>
  
  <p>How to achieve the same result using subquery </p>