Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:06:17+00:00 2026-06-11T03:06:17+00:00

Im trying to run this query to Update member points When the member points

  • 0

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()}';

    ";

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:06:18+00:00Added an answer on June 11, 2026 at 3:06 am

    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:

    UPDATE engine4_event_membership a join
           engine4_event_events b
           on b.event_id = a.resource_id
        SET a.points = a.points + b.prize 
        WHERE a.resource_id = '{$this->event->getIdentity()}' and
              a.points = (select max(a2.points)
                          from engine4_event_membership a2
                          where a2.resource_id a.resource_id
                         )
    

    This will probably get the same MySQL error. So, the WHERE clause needs to be moved to the joins:

    UPDATE engine4_event_membership a join
           engine4_event_events b
           on b.event_id = a.resource_id join
           (select resource_id, max(points) as maxpoints
            from engine4_event_membership
            group by resource_id
           ) amax
           on a.resource_id = amax.resource_id and
              a.points = amax.points
        SET a.points = a.points + b.prize 
        WHERE a.resource_id = '{$this->event->getIdentity()}'
    

    The inability to use the target table in a correlated subquery is a limitation in MySQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run a simple query with node-mysql like this: client.query(UPDATE mytable SET
Hi I am trying to run this query in SQL but it is not
Hey guys I am getting this exception when trying to run the query Column
I am trying to run this update statement but informix doesn't allow me to.
I'm trying to run the following query using phpMyAdmin: UPDATE TABLE x SET `number`
I am trying to run a simple Update query on a certain set of
I am trying to run a query to update the value of a custom
I am trying to run this: $stmt=$cxn->prepare(UPDATE table1 SET used='1' WHERE prim_id != (SELECT
I'm currently trying to run a LINQ query over a MS SQL database. This
I'm trying to run this code but this error appear: Uncaught TypeError: string is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.