Im trying to run this query to Update member points When the member points equals the max value? to set the winner prize… but im getting this error.. thanks
Error: 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 ‘WHERE a.points = max(a.points) AND b.event_id = 4’ at line 4
$sql="
UPDATE engine4_event_membership a
INNER JOIN engine4_event_events b ON b.event_id = a.resource_id
SET a.points = a.points + case b.prize
WHERE a.points = max(a.points) AND b.event_id = '{$this->event->getIdentity()}';
";
If I’m understanding the data structure correctly, you can do this with a correlated subquery in the WHERE clause.
You are updating the membership table where resource_id is the input identity. You are looking for record(s) that have the maximum points. The following should do this:
This will probably get the same MySQL error. So, the WHERE clause needs to be moved to the joins:
The inability to use the target table in a correlated subquery is a limitation in MySQL.