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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:53:12+00:00 2026-06-15T03:53:12+00:00

I have an SQL query to update the rotational offset of a photo. The

  • 0

I have an SQL query to update the rotational offset of a photo. The query should add 1 to the value, unless the value is 3, in which case it should set it back to 0 (as in, 4 lots of 90 degrees rotation is the same as no rotation at all).

I’m not sure if what’s below is the most efficient way to do it, and I’d appreciate suggestions of simpler solutions that don’t require me to list out the mappings like I have.

However, my question is, why do I get a MySQL syntax error? When I use the SELECT subquery on it’s own, it returns the result as expected.

UPDATE `photos` p SET p.rotational_offset=map.new_value INNER JOIN (
SELECT 0 AS rotational_offset, 3 AS new_value
UNION SELECT 1 , 0
UNION SELECT 2 , 1
UNION SELECT 3 , 2
) map ON p.rotational_offset=map.rotational_offset WHERE p.photo_id="22";
  • 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-15T03:53:13+00:00Added an answer on June 15, 2026 at 3:53 am

    First, a much simpler solution is to use the MOD operator (%):

    UPDATE photos
    SET rotational_offset = (rotational_offset + 1) % 4
    WHERE photo_id = '22'
    

    See it working online: sqlfiddle


    And now to actually answer your question… You get an error because you aren’t using the correct syntax for a multiple table update. The table references come first, before the SET clause. The correct syntax is as follows:

    UPDATE [LOW_PRIORITY] [IGNORE]
    table_references
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]
    

    Your statement doesn’t work because you put the inner join after the SET clause. A corrected version is as follows:

    UPDATE photos AS p
    INNER JOIN
    (
        SELECT 0 AS rotational_offset, 3 AS new_value
        UNION ALL SELECT 1 , 0
        UNION ALL SELECT 2 , 1
        UNION ALL SELECT 3 , 2
    ) AS map
    ON p.rotational_offset = map.rotational_offset 
    SET p.rotational_offset=map.new_value
    WHERE photo_id = '22'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL update query: UPDATE table1 SET table1.field1 = 1 WHERE table1.id
I have an SQL query that takes the following form: UPDATE foo SET flag=true
I have a SQL query that goes like this: UPDATE User SET flag='Y' WHERE
I have this SQL query, which is wrong. I want to update the field
I have Sql-query ike this: UPDATE tProfile SET LastActivity=@DateTimeNow WHERE UserId=@UserId AND Id IN
I have following SQL UPDATE query: UPDATE Invoices SET Price = (SELECT SUM(Price*ProductsAndServices.Amount) FROM
I have used function substr in my sql query: UPDATE staff SET dept_id='.$department.', SUBSTR(auth,
**Update: Title should have read: Sql Query - Unique item with latest entry Hi
I have this SQL-Server query UPDATE qryPETEUR_frmPricingModel() SET G&A = '68442.0000' WHERE comp_id =
I have this SQL-Server query UPDATE qryPETEUR_frmPricingModel() SET [%debtToEBITDA] = '498116.0000' WHERE comp_id =

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.