I've recently started working on MySQL n right now i want to create a trigger but MySQL is returning an error in my syntax.
delimiter $$;
create trigger abc after insert on ratings
for each row
begin
set @n1 = select avg(rating) from ratings join users where ratings.uname=users.uname
and ratings.bookid=new.bookid users.`type`='admin' or users.`type`='critic';
update books set avgcriticrating = @n1 where bookid=new.bookid;
end;
The select statement runs perfectly when fired on its own but gives an error when i use it inside of the trigger.
Here's the error that MySQL gives
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select avg(rating) from ratings join users where ratings.uname=users.uname an' at line 4
Both the books and ratings table contain a field called bookid.
please help