betweenGo

SQL Insert in One Table Based on Values in Another Table

by on Jan.18, 2010, under Oracle

Love's Old Sweet Song on Flickr

(Photo: Love’s Old Sweet Song by linda yvonne)

The syntax for doing this is similar to doing an update in one table based on values in another table yet simpler.

INSERT INTO suppliers (name)
SELECT customers.name
  FROM customers
  WHERE customers.id = suppliers.id);

If you want to add constant values into the insert you can do something like this.

INSERT INTO suppliers (name, city)
SELECT customers.name, 'Toronto'
  FROM customers
  WHERE customers.id = suppliers.id);

For further reading please see SQL INSERT INTO.


Share

Related posts:

  1. SQL Update in One Table Based on Values in Another Table
  2. SQL Delete in One Table Based on Values in Another Table
  3. Sequences on Oracle
  4. Inserting a text value with special characters
  5. How to Alter Table

:

Leave a Reply

 

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!