Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. MySql 1093 Error: You can't specify target table 'c1' for update in FROM clause

MySql 1093 Error: You can't specify target table 'c1' for update in FROM clause

Scheduled Pinned Locked Moved Database
databasemysqlhelpannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abhinav_007
    wrote on last edited by
    #1

    I am trying to execute the following update query:

    update committees c1 set num_subcommittees =
    case
    when parent_committee is not null then -1
    else (select count(*) from committees c2 where c2.parent_committee = c1.id)
    end;

    But instead getting mySql 1093 error. The table structure is like this:

    CREATE TABLE `committees` (
    `id` char(5) NOT NULL,
    `parent_committee` char(5) DEFAULT NULL,
    `name` char(200) DEFAULT NULL,
    `chairman` char(40) DEFAULT NULL,
    `ranking_member` char(40) DEFAULT NULL,
    `num_subcommittees` int(11) DEFAULT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    Please comment.

    A 1 Reply Last reply
    0
    • A Abhinav_007

      I am trying to execute the following update query:

      update committees c1 set num_subcommittees =
      case
      when parent_committee is not null then -1
      else (select count(*) from committees c2 where c2.parent_committee = c1.id)
      end;

      But instead getting mySql 1093 error. The table structure is like this:

      CREATE TABLE `committees` (
      `id` char(5) NOT NULL,
      `parent_committee` char(5) DEFAULT NULL,
      `name` char(200) DEFAULT NULL,
      `chairman` char(40) DEFAULT NULL,
      `ranking_member` char(40) DEFAULT NULL,
      `num_subcommittees` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

      Please comment.

      A Offline
      A Offline
      Afzaal Ahmad Zeeshan
      wrote on last edited by
      #2

      What is c1? Just use committees to update the table. PHP Update Data in MySQL[^]

      The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups