I have 3 tables in my SQL Server database named College
, University
, OldSyllabus
.
Table College
has 1000 rows with columns such as DateOfJoining
, studentName
Table University
has 50 rows with columns such as DateOfCourseRevision
, courseName
I need to write an insert statement to push records in table OldSyllabus
by comparing University
table DateOfCourseRevision
column with College
table DateOfJoining
column
All records from College
table to be inserted into OldSyllabus
by comparing the DateOfCourseRevision <= DateOfJoining
Query:
INSERT INTO [OS].[OldSyllabus] (StudenName, Address)
VALUES
((SELECT C.Name
FROM [COL].[College] AS c
INNER JOIN [UNI].[University] AS u ON c.CourseName = u.CourseName
AND c.Date <= u.Date),
(SELECT C.Address
FROM [COL].[College] AS c
INNER JOIN [UNI].[University] AS u ON c.CourseName = u.CourseName
AND c.Date <= u.Date))
I get an error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.