Home > front end >  How to insert values into database table from select statement SQL
How to insert values into database table from select statement SQL

Time:11-30

ID Name Class Date Intime Outtime INAM OUTPM
1001 Paul 1st 29-11-2022 Holiday Holiday H H

Query:

SELECT DISTINCT 
    COALESCE(tt.ID, t1.ID) AS ID,
    COALESCE(tt.Name, t1.Name) AS Name,
    COALESCE(tt.Class, t1.Class) AS Class,
    tt.Date, tt.Intime, tt.Outtime, tt.INAM, tt.OUTPM   
FROM 
    stuattrecordAMPM AS t1
CROSS JOIN 
    (SELECT * FROM stuattrecordAMPM  
     UNION ALL
     SELECT 
         NULL, NULL, NULL, Date, Holiday_Name, Holiday_Name,
         Status, Status 
     FROM HolidayList) AS tt 
ORDER BY
    [ID]

In this code result showing as above table values. I want to insert values into stuattrecordAMPM. How can I use INSERT with the SELECT statement? Could someone help me? Thank you...

CodePudding user response:

Hope you are looking for select statement result output to another table input. Please use standard sql for your needs.

  insert into target_table(id,name)
        select id,name from my_table;
  •  Tags:  
  • sql
  • Related