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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:16:10+00:00 2026-06-11T12:16:10+00:00

I need to create a MySQL query with an IF statement. Here is a

  • 0

I need to create a MySQL query with an IF statement. Here is a database schema:

CREATE DATABASE my_db;
USE my_db;
CREATE TABLE IF NOT EXISTS if_table(
    id INTEGER unsigned,
    field_1 INTEGER unsigned,
    field_2 INTEGER unsigned,
    field_3 INTEGER unsigned,
    PRIMARY KEY (id)
);

How do I write an UPDATE query which corresponds to next pseudo code?

if field_2 equals 0 then field_1 = field_1 + 1
else field_3 = field_3 + 2 
where id == 1
  • 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-11T12:16:11+00:00Added an answer on June 11, 2026 at 12:16 pm

    Try this in-line IF statement

    SELECT IF(field_2 = 0, field_1 + 1, field_3 + 2) AS `Result`
    FROM tableName
    WHERE ID = 1
    

    or if you want to update the value,

    UPDATE tableName
    SET field_1 = IF(field_2 = 0, field_1 + 1, field_1),  
        field_3 = IF(field_2 = 0, field_3, field_3 + 2)
    WHERE ID = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a simple mySQL database with a field for an image.
I need to create a table in MySQL which stores the different currency symbols
I need to create pdf document which outputs all rows from mysql table, but
In MySQL, I need to create a new table called users with the following
I'm using Rails 3 with a MySQL database, and I need to programmatically create
UPDATED: I am using MySQL statement to create a view: I need to show
I'm having a problem with my MySQL statement. I need a query that counts
I need to create a MySQL query that generates 4 rows for each row
I need to use a variable to indicate what database to query in the
So here I am and need to see some results from a MYSQL database

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.