Home > Mobile >  How to insert values into database SQL
How to insert values into database SQL

Time:12-11

Table studentdata:

ID Name Class
1001 Paul 1st

Table HolidayList:

Date Holiday_Name Status
11-12-2022 Sunday H

Output:

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

Code:

SELECT
    studentdata.ID, studentdata.Name, studentdata.Class,
    HolidayList.Date AS Date, HolidayList.Holiday_Name AS Intime,
    Holiday_Name AS Outtime, HolidayList.Status AS INAM,
    HolidayList.Status AS OUTPM 
FROM
    studentdata 
CROSS JOIN 
    HolidayList 

From this code, I'm getting the output shown, but how can I insert these values into table1 in my database? Thank you...

CodePudding user response:

To insert the values from the "Output1" table into a database table, you can use the INSERT statement in SQL. Here is an example of how to do this:

-- Connect to the database
CONNECT TO 'database_name' USER 'username' IDENTIFIED BY 'password';

-- Insert the values from Output1 into table1
INSERT INTO table1 (ID, Name, Class, Date, Intime, Outtime, INAM, OUTPM)
SELECT ID, Name, Class, Date, Intime, Outtime, INAM, OUTPM
FROM Output1;

Note that this example assumes that the Output1 table already exists and contains the values that you want to insert into the table1 database table.

  •  Tags:  
  • sql
  • Related