title: How to do update/migration of data, with help of generic query
body: <p>I am in middle of trying to get better with sql, but I have some issue/question with one of my exercies.
  So I thought about this kind of following situation.
  I have three tables:</p>
  <p><code>STUDENT</code></p>
  <pre><code>+----+-------+----------+
  | ID | NAME  |  LEVEL   |
  +----+-------+----------+
  |  1 | Tom   | beginner |
  |  2 | Peter | expert   |
  |  3 | Kate  | beginner |
  |  4 | John  | beginner |
  +----+-------+----------+
  </code></pre>
  <p><code>COURSE</code></p>
  <pre><code>+----+-----------+
  | ID |   NAME    |
  +----+-----------+
  |  1 | Math      |
  |  2 | English   |
  |  3 | French    |
  |  4 | Chemistry |
  +----+-----------+
  </code></pre>
  <p><code>STUDENT_COURSE</code></p>
  <pre><code>+------------+-----------+
  | STUDENT_ID | COURSE_ID |
  +------------+-----------+
  |          1 |         1 |
  |          1 |         2 |
  |          3 |         1 |
  |          4 |         3 |
  +------------+-----------+
  </code></pre>
  <p>But after some time I have requirments to divide courses into more specific names.</p>
  <pre><code>Math      -&gt; Math_Beginner, Math_Expert
  English   -&gt; English_Beginner, English_Expert
  French    -&gt; French_Beginner, French_Expert
  Chemistry -&gt; Chemistry_Beginner, Chemistry_Expert
  </code></pre>
  <p>So in <code>COURSE</code> table whould looks like that</p>
  <pre><code>+----+--------------------+
  | ID |        NAME        |
  +----+--------------------+
  |  1 | Math_Beginner      |
  |  2 | English_Beginner   |
  |  3 | French_Beginner    |
  |  4 | Chemistry_Beginner |
  |  5 | Math_Expert        |
  |  6 | English_Expert     |
  |  7 | French_Expert      |
  |  8 | Chemistry_Expert   |
  +----+--------------------+
  </code></pre>
  <p>And know I am in point when I am stuck. Because I need to update <code>STUDENT_COURSE</code> too. Obviously I can do it with hardcoded values, but in case of table where I have thousends of entries it would take a lot of time.
  So I was thinking about more generic approach.
  Student does containt column where <code>LEVEL</code> is stored, and it is corresponding with suffix of course name. So I would like to use it.</p>
  <pre><code> UPDATE student_course
  SET    course_id = ( here i would need TO have CURRENT value OF course.NAME
  AND    student.level,
  ANDIF it was math
  AND    level IS beginner i would put math_beginner ) 
  
  </code></pre>
  <p>Any idea how could I do this kind of migration(I suppose calling it migration is too much)</p>