SQL Tutorial – 13: Inserting Data Into a Table From Another Table




In this tutorial we’ll learn to use the INSERT Query to copy data from one table into another.

Original source


35 responses to “SQL Tutorial – 13: Inserting Data Into a Table From Another Table”

  1. Hello , Nice tutorial. I have one quick question.
    What if I have 2 Tables.
    1) EMP_DATA
    2) SALARY_DATA
    COLUMNS:
    1) EMP_DATA ( EMP_ID, First_Name, Last_Name)
    2) SALARY_DATA ( EMP_ID, Salary, Dept)
    Situation: I want to create a new table EMP_DATABASE which has fields EMP_ID, First_Name, Last_Name, Salary, Dept. I want to copy all the data from table EMP_DATA and SALARY_DATA into a newly created table EMP_DATABASE. What should be the syntax for it.
    I would really appreciate your help. You can also email me on chavan.rahul70595@gmail.com

  2. Hai
    Sir,

    Actually, I want some clarification, I have a dynamic table If that table entry how to insert the next table. It should be inserted at a time,
    In dynamic table create in every month(It ie use of exe) .can you please answer me sir,

  3. Is it possible to use this INSERT command to add a computed column from table 1 (source) to destination? My syntex (shown below) works for calculating running total however, it doesn't work if i try to use same query to insert running total to new table;

    select t_date, amount,
    sum(amount) over (order by t_date) as balance
    from bank
    order by t_date;

    If i add one additional line as your video "INSERT INTO new_tb (t_date, amount, balance), the balance column in new_tb is still zero.

    Any input would be highly appreciated.

  4. insert INTO employee(en_cust_id) SELECT id FROM customer where name = 'avi'

    Error Code: 1364. Field 'emp_id' doesn't have a default value

    can anybody tell me why i am getting this error?

    en_cust_id –>fk of employee table
    'emp_id'–> pk of employee table
    'id'–>is pk of customer table

  5. in the previous slide you had us delete emp_info, but in this video you have that table present. You should have had us re-create that table so we can stay in sync with you. Maybe you were just testing us to have us create it again.

  6. Can this method be used like a draft table scenario?

    So, the insert query copies the data over to the live table with the first table taking the data as the 'draft table'?

Leave a Reply