SQL - Insert Into table based on a counter value
<p>I have tabA:</p>

<pre><code>________________________
|ID  |EMPLOYEE|CODE    |
|49  |name1   |mobile  |
|393 |name2   |none    | 
|3002|name3   |intranet|
________________________
</code></pre>

<p>The ID column (tabA) is based on a counter in the below tabB:</p>

<pre><code>_________________
|TYPE       |ID  |
|intranet   |3003|
|mobile     |50  | 
|none       |394 |
__________________
</code></pre>

<p>I want to insert new row in tabA using the ID counter (as it is the next available ID). How do I insert into table based on a counter value?</p>

<p>I am trying this method, which results in trying to insert a duplicate type, instead of the max(ID):</p>

<pre><code> INSERT INTO tabA (ID, EMPLOYEE, CODE)  
</code></pre>

<p><code>VALUES ((select max(ID) from tabB where TYPE = 'A'),name4,'intranet');</code></p>

<p>I expect to see tabA:</p>

<pre><code>________________________
|ID  |EMPLOYEE|CODE    |
|3000|name1   |mobile  |
|3001|name2   |none    | 
|3002|name3   |intranet|
|3003|name4   |intranet|
________________________
</code></pre>

<p>tabB:</p>

<pre><code>_________________
|TYPE       |ID  |
|mobile     |2999|
|none       |3002| 
|intranet   |3004|
__________________
</code></pre>