Friday, January 16, 2015

SQL: INSERT by copying values of existing columns of a table - Insert in combination of Select

For example, you have a table A, which has columns Col1, Col2, ...........Col20. You now want to copy the values of Col2, Col5, Col7 to a new table B for some reason such as allow more people to access the data. Table B has three columns: Field1, Field2, Field3.

This is the SQL to do it.

      INSERT INTO B (Field1, Field2, Field3)
      SELECT Col2, Col5, Col7
      FROM A
      WHERE Col1 > to_date("11/12/2000", "mm/dd/yyyy");


References

1. SQL: INSERT by copying values from existing records for some columns and using other values for other columns - Insert in combination of Select

2. SQL: INSERT by copying values from two tables - Insert in combination of Select


                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment