Jump to content

Advanced Mysql Query Error


seventheyejosh

Recommended Posts

I am getting this error:

 


#1093 - You can't specify target table 'users' for update in FROM clause

 

From this query:

 


UPDATE
`users`
SET
`users`.`distinctions`=CONCAT(`users`.`distinctions`,'12,')
WHERE
`users`.`id`
IN(
    SELECT
    DISTINCT `abstract_authors`.`userid`
    FROM
    `abstract_authors`
    INNER JOIN
    `users`
    ON
    `users`.`id`=`abstract_authors`.`userid`
    WHERE
    `abstract_authors`.`abstractid`
    IN(
        SELECT
        `abstracts`.`id`
        FROM
        `abstracts`
    )
)

 

Can anyone enlighten me as to what is going on?

 

Basically I need to update the users table. I'm doing the first IN() to get all of the author id's, and the second IN() (top down) to get only the author entries that have an active abstract. Some of the abstracts when deleted weren't removing their author ties, initially.

 

Thanks a lot!

 

- Josh

Link to comment
Share on other sites

Well i googled a bit, and figured it out. Since I was already backing up the big users table, I just referenced it instead in the inner IN();

 


UPDATE
`users`
SET
`users`.`distinctions`=CONCAT(`users`.`distinctions`,'12,')
WHERE
`users`.`id`
IN(
    SELECT
    DISTINCT `abstract_authors`.`userid`
    FROM
    `abstract_authors`
    INNER JOIN
    `users_backup_jo_0421` AS `users_2`
    ON
    `users_2`.`id`=`abstract_authors`.`userid`
    WHERE
    `abstract_authors`.`abstractid`
    IN(
        SELECT
        `abstracts`.`id`
        FROM
        `abstracts`
    )
)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.