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 5847173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:40:51+00:00 2026-05-22T12:40:51+00:00

I want my query to using a IF statement, identify; if the current num_unmarked

  • 0

I want my query to using a IF statement, identify; if the current num_unmarked will become 0 after this update, then also set is final to ‘YES’.

so here is my query:

 $sql = "UPDATE results_tb 
                    SET 
                        num_unmarked = num_unmarked - 1,
                        is_final=IF( num_unmarked-1=0, 'YES', is_final ),
                        score = score + $awarded
                    WHERE 
                        user_id = $student 
                    AND 
                        test_id = $test 
            ";

what is actually happening is, the query runs, num_unmarked decrements and score is updated however even if num_unmarked is 1 (not 0) it still sets is_final to ‘YES’.

could somebody tell me what I am doing wrong please or enlighten me to a better way? (i am nooby :D)

thanks,

  • 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-05-22T12:40:52+00:00Added an answer on May 22, 2026 at 12:40 pm

    The updates are processed sequentially in MySql, so the update to num_unmarked occurs before the IF statement, and the IF statement uses the newly updated value. So you actually want to use the value as if it has already been updated, i.e., compare it directly to 0:

    is_final = IF(num_unmarked=0, 'YES', is_final),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
I'm using EF for a set of objects and want to query one type
Q: Please , i want to ask ,how to perform a query(select statement) using
I want to dispaly column in datagrid view using custom query statement but i
I have a DataGridView that I want to query using Linq (C# WinForm). I
I want to write an SQL query using the LIKE keyword. It should search
I am using mssql and I want to make a query that returns a
I am using Xpath in Ruby with following statement. print XPath.first(Document.new(html),//tr[@id='ctl00_c1_rr_ci_trAdd']//td[2]) The Query return
I am using following statement in select portion of the query: extract(XMLTYPE(doc.payload),'/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/DOCUMENTID') it works
I'm using postgres (postgis) and i want to perform a query that returns all

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.