title: How to add columns in select list SQL which are rows of other table : SQL Server 2008
body: <p>I have a scenario where I need help. I have a table from where I'm pulling <strong>Max</strong> data group by <strong>ID</strong> like below.</p>
  
  <pre><code>select ID, max(basic) as B, max(hra) as H
  from #temp
  group by ID
  </code></pre>
  
  <p>I have another table (only one column) where I have certain values. Number of rows or data of this table is dynamic. X and Y are just random data. There could be many rows with any <em>varchar</em> data.</p>
  
  <pre><code>select * from #dummy
  </code></pre>
  
  <p>Now I need rows of #dummy table as columns of #temp like below.</p>
  
  <p><a href="https://i.stack.imgur.com/PZ3CP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PZ3CP.png" alt="enter image description here"></a></p>
  
  <p>Earlier I was thinking of pivoting but it won't work as there is no relation between these two tables. Any help, TIA.</p>