title: Clean up SQL Server script
body: <pre><code>SELECT pp.pat_key, MAX(pp.PROV_NPI) [Provider_ID], CONCAT(pp.LAST_NM,' ',pp.FIRST_NM) [Provider_Name]
    INTO pat_primary_provider
    FROM TRDW.dbo.PATIENT_PROVIDER pp
    WHERE IS_PCP=1
    AND pat_key IN (SELECT Consumer_ID FROM CareWire0521)
  GROUP BY pp.PAT_KEY, pp.last_nm, pp.FIRST_NM;
  
  SELECT ppp.*
    INTO ppp1
    FROM (SELECT PAT_KEY, MAX(provider_ID) AS maxprov FROM pat_primary_provider GROUP BY PAT_KEY) AS x 
    INNER JOIN pat_primary_provider AS ppp ON ppp.PAT_KEY = x.PAT_KEY AND ppp.Provider_ID = x.maxprov; 
  </code></pre>
  
  <p>I need to get the results of <code>ppp1</code> only using one query (no <code>INTO</code> statements) in SQL Server. Please help.</p>