2

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...

Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
user3145732
  • 29
  • 1
  • 7

1 Answers1

3

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 
zzlalani
  • 22,960
  • 16
  • 44
  • 73
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83