Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert data from one table data to another table
    primarykey
    data
    text
    <p>I have two tables <code>TAB1</code> and <code>TAB2</code>. I want to insert data in <code>TAB2</code> in a particular column. I want to insert data that has to be fetched from the <code>TAB1</code> on <code>WHERE</code> condition. If fethced data is there, then insert data in <code>TAB2</code>. If NOT, insert blank in <code>TAB2</code> </p> <p>Here I am talking about single column only. I am inserting some other data also. Can it happen in as single SQL Query. I am using Oracle.</p> <p>Here is my demo code. I need something like this:</p> <pre><code>INSERT INTO TAB1('value1','value2',?) if exists(select king from TAB2 where queen='yash' ) ?=select king from TAB2 where queen='yash' if not exists ?='' </code></pre> <p><code>TAB1</code> and <code>TAB2</code> are having different type of columns.</p> <pre><code> TAB1 TAB2 -------- ----------------- col1 col2 col3 col4 col1 king Queen ----------------- ---------------- 1 jan King Robin 1 Alex yash 2 Feb King2 Hood 2 Jhon Shakthi </code></pre> <p>Now I want to insert data in TAB1 from TAB2 with where condition Something like this </p> <pre><code>insert into TAB1(col1,col2,col3,col4) values(5,'MArch',King7, select king From TAB2 where Queen='yash') </code></pre> <p>If select king From TAB2 where <code>Queen='yash'</code> returns <code>'Alex'</code> then that has to be inserted if not blank value has to be inserted.</p> <pre><code> Here Queen column is Unique column .. So you can expect single row data only. TAB1 and TAB2 having different column names and different column Types </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload