title: SQL Advance, creating fill new column with coditional value
body: <p>Cound you please support with question below, i trying to fill a new colmn in my SQL query based in a conditional value.</p>
  <p>pseudo code:</p>
  <pre><code>IF ap_id exists in visit_table and visit_type = 'first'
  then firs_tvisit_id = visit_table.visit_id and first_visit_user = visit_table.Username
  </code></pre>
  <ul>
  <li>The same logic for second and third visit.</li>
  </ul>
  <p>This are visit_table.</p>
  <p><a href="https://i.stack.imgur.com/k6mWo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k6mWo.png" alt="enter image description here" /></a></p>
  <p>And this are ap_table (where are the key values):</p>
  <p><a href="https://i.stack.imgur.com/sikS0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sikS0.png" alt="enter image description here" /></a></p>
  <p>And below is the expected table.</p>
  <p><a href="https://i.stack.imgur.com/pFvqB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pFvqB.png" alt="enter image description here" /></a></p>
  <p>SQL is able to make these kind of data manipulation, if there are how can i get this.</p>
  <p>I alrady tryed left joins, inner joins, and full outher join. however i were not able to create a new column and fill this based in a conditional.</p>