Joachim Hollekim Joachim Hollekim - 5 months ago 13
SQL Question

Using the Concat expression with a join

I'm trying to append the names of a number of fields with certain criteria.

This works fine:

select * from course
left join courseterm on course.courseID = CourseTerm.courseID
where courseterm.termID like 1 or 2
and course.expires not like '0000-00-00 00:00:00'


This also works fine:

UPDATE course SET course.Title = CONCAT(`Title`, ' ');


However, this tells me that I have an error in my syntax:

update course
set course.title = CONCAT('2015/2016-',`Title`)
left join courseterm on course.courseID = CourseTerm.courseID
where courseterm.termID like 1 or 2
and course.expires not like '0000-00-00 00:00:00';


I can't figure out what's wrong. Anyone?

Answer

The set clause must be after the table and join

update course
left join courseterm on course.courseID = CourseTerm.courseID
set course.title = CONCAT('2015/2016-',`Title`)
where courseterm.termID like 1 or  courseterm.termID=2 
and course.expires not like '0000-00-00 00:00:00';
Comments