What is the correct UPDATE query for MySQL?

This question is in reference to Atlassian Documentation: Unable to move issue to another Issue Type due to 'The issue type selected is invalid' error

I am trying to run this update query:

INSERT INTO optionconfiguration VALUES ((SELECT MAX(id)+1 FROM optionconfiguration), 'issuetype', '10004', 10000, (SELECT MAX(sequence)+1 FROM optionconfiguration WHERE fieldconfig=10000));

 

And I am getting an error:

INSERT INTO optionconfiguration VALUES ((SELECT MAX(id)+1 FROM optionconfiguration), 'issuetype', '10004', 10000, (SELECT MAX(sequence)+1 FROM optionconfiguration WHERE fieldconfig=10000)) Error Code: 1093. You can't specify target table 'optionconfiguration' for update in FROM clause 0,035 sec

I think its related to this issue with inner queries. Any idea how to turn this SQL statement to correct one?

1 answer

The error is likely due to the fact that you are referencing the same table in the INSERT and the subqueries.  All I can suggest offhand is inserting into a temporary table, then inserting the result(s) to optionconfiguration.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published 13 hours ago in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

335 views 5 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you