combine selected columns from two tables and store it in another table in the db

487 Views Asked by At

Hi I want to combine selected columns from two tables and store those values into another table.

example im having a table name

class - classname location

and another table

student - studentid, name, classname

Attendance - combining the two tables only selected columns.

i.e studentid , classname, location

Tell how to insert the values into my table attendance.

Thanks in Advance...

1

There are 1 best solutions below

0
On

You should use INSERT...SELECT

INSERT INTO Attendance (studentid , classname, location)
SELECT s.studentid, c.classname, c.location
FROM class c 
INNER JOIN student s ON c.classname = s.classname