Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Error Code: 1093. You can't specify target table 'table' for update in FROM clause

Powerful Penguin answered on June 15, 2023 Popularity 6/10 Helpfulness 3/10

Contents


More Related Answers

  • You can't specify target table 'Person' for update in FROM clause
  • mysql #1093 - You can't specify target table error
  • update you can't specify target table for update in from clause

  • Error Code: 1093. You can't specify target table 'table' for update in FROM clause

    0

    Short answer: use `(SELECT * FROM myTable) AS something`

    The problem is that MySQL, for whatever inane reason, doesn't allow you to write queries like this:

    UPDATE myTable

    SET myTable.A =

    (

    SELECT B

    FROM myTable

    INNER JOIN ...

    )

    That is, if you're doing an UPDATE/INSERT/DELETE on a table, you can't reference that table in an inner query (you can however reference a field from that outer table...)

    The solution is to replace the instance of myTable in the sub-query with (SELECT * FROM myTable), like this:

    UPDATE myTable

    SET myTable.A =

    (

    SELECT B

    FROM (SELECT * FROM myTable) AS something

    INNER JOIN ...

    )

    This apparently causes the necessary fields to be implicitly copied into a temporary table, so it's allowed 

    Popularity 6/10 Helpfulness 3/10 Language sql
    Tags: clause sql target
    Link to this answer
    Share Copy Link
    Contributed on Jun 15 2023
    Powerful Penguin
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.