title: SELECT DISTINCT values and INSERT INTO table
body: <p>I want to take a column with values that repeat multiple times and get that value only once and store it for later use, but at the same time I would like to get another value in the same row as that distinct column.</p>
  
  <pre><code>A      B       C
  32263  123456  44
  32263  123456  45
  32263  123456  46
  32264  246802  44
  32263  246802  45
  32264  246802  46
  32265  369258  44
  32265  369258  45
  32265  369258  46
  </code></pre>
  
  <p>A, B, C represent three columns. Ignore C for now.</p>
  
  <p>My question is: How can I get this information in this table and store it for I can use it later in the script?</p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>use databaseName
  
  select distinct A from tableName
  order by A
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>A
  32263
  32264
  32265
  </code></pre>
  
  <p>I'm trying to get it to also give me B's value. (Note it does not matter at all which row I get since no matter what A I choose the value of B will be the same for given A.) We are ignoring C for now.</p>
  
  <p>The result should be:</p>
  
  <pre><code>A      B
  32263  123456
  32264  246802
  32265  369258
  </code></pre>
  
  <p>Now, once I get it like that I want to insert a row using the values I got from the query. This is where C comes in. I want to do something like this:</p>
  
  <pre><code>use databaseName
  
  insert into tableName (A, B, C)
  values (32263, 123456, 47)
  </code></pre>
  
  <p>Of course I don't want to put the values directly inside of there, instead have some type of loop that will cycle through each of the 3 distinct A values I found.</p>
  
  <p>In short, my table should go from:</p>
  
  <pre><code>A      B       C
  32263  123456  44
  32263  123456  45
  32263  123456  46
  32264  246802  44
  32263  246802  45
  32264  246802  46
  32265  369258  44
  32265  369258  45
  32265  369258  46
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>A      B       C
  32263  123456  44
  32263  123456  45
  32263  123456  46
  32263  123456  47 -
  32264  246802  44
  32263  246802  45
  32264  246802  46
  32264  246802  47 -
  32265  369258  44
  32265  369258  45
  32265  369258  46
  32265  369258  47 -
  </code></pre>
  
  <p>I placed dashes next to the newly added rows to help you see the changes.</p>
  
  <p>I figure I should perhaps do some type of loop that will cycle through all three distinct A values, but my problem is how to do that?</p>
  
  <p>Thanks for your time.</p>