Solve mysql 1093 error in modifying table records

Source: Internet
Author: User

Solve the 1093 error in modifying table records in mysql. requirement: known TABLE information: TABLE Name: frjg TABLE structure: [SQL] DROP TABLE IF EXISTS 'frjg'; CREATE TABLE IF NOT EXISTS 'frjg' ('id' int (11) not null AUTO_INCREMENT, 'jgbh' varchar (3) character set utf8 not null comment 'Organization No. ', 'jgmc' varchar (50) character set utf8 not null comment 'institution name', 'jgm' varchar (8) character set utf8 not null comment' institution Code ', 'htqssj' date not null comment' contract start time', 'htyxsj 'date NOT Null comment 'Contract validity time', 'dxfsl 'int (11) not null comment' total message sending amount', 'dxsyl' int (11) not null comment' remaining message margin ', 'mbkhl' int (11) not null comment' target customer volume ', 'cjsj 'datetime not null comment' creation time ', 'lastactive' datetime not null comment' last operation time', 'xmmc 'varchar (50) character set utf8 not null comment' project name', 'cjr 'varchar (50) character set utf8 default null comment 'creator ', 'state' int (11) NOT NULL DEFAU LT '1' comment' Current status of the legal representative, 0: Normal, 1: Disabled, 'weight' int (11) DEFAULT '0' comment' weight, when the birth volume is small, determine who is assigned, 'spyz' int (11) DEFAULT '0' comment' approval criteria. When this flag is exceeded, the task is suspended and the SMS notification is sent ', 'jgjc' varchar (50) default null comment' organization abbreviation ', primary key ('id') ENGINE = MyISAM default charset = gbk AUTO_INCREMENT = 121; -- data in the table to be stored 'frjg' -- insert into 'frjg' ('id', 'jgbh', 'jgmc ', 'jgm', 'htqssj', 'htyxsj ', 'dxfsl ', 'dxsyl', 'mbkhl', 'c Jsj ', 'lastactive', 'xmmc', 'cjr ', 'state', 'weight', 'spbz', 'jgjc') VALUES (1, '001 ', 'provincial management Center', '123', '2017-08-29 ', '2017-09-01', 27000099 000, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00 ', 'test2', 'zichen', 0, 0, 0, NULL), (2, '002', 'linwei district joint management Center ', '123', '2017-08-29 ', '2017-09-01', 27050199 973, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00 ', 'test2', 'zichen', 0, 0, 0, NULL), (3, '003 ', 'xincheng district joint management Center', '000000', '2017-08-29', '2017-09-01 ', 27011399 954, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2', 'zichen', 0, 0, 0, NULL), (4, '004 ', 'management center of the Beilin District Association', '20170101', '2017-08-29 ', '2017-09-01', 27010199 977, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2', 'zichen', 0, 0, 0, NULL), (5, '005 ', 'zhuqiao Social Security Management Center', '123', '2017-08-29', '2017- 09-01 ', 200000,199 975, 10000, '2017-07-26 00:00:00', '2017-08-08 15:38:00 ', 'test2', 'zichen', 0, 0, 0, NULL), (6, '006 ', 'yanta social media management Center', '000000', '2017-08-29', '2017-09-01 ', 27010299 871, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2', 'zichen', 0, 0, 0, NULL), (7, '007 ', 'weiyang District Association Management Center', '1234568', '2017-08-29', '2017-09-01 ', 27010399 928, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00 ', 'test2', 'zichen', 0, 0, 0, NULL), (8, '008', 'lianhu social management Center', '123 ', '2017-08-29 ', '2017-09-01', 2012 960, 2014, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2 ', 'zichen', 0, 0, 0, NULL), (9, '009', 'linhu social management Center', '123', '2017-08-29 ', '2017-09-01 ', 2014 990, 200000,199, '2017-07-26 00:00:00', '2017-08-08 15:38:00 ', 'test2', 'zichen', 0, 0, 0, NULL), (10, '010 ', 'yanliang district, Xi'an Club Management Center ', '1234568', '1997-08-29', '2017-09-01 ', 27010799 978, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00 ', 'test2', 'zichen', 0, 0, 0, NULL), (11, '011 ', 'chang 'an district credit union management center ', '123', '2017-08-29', '2017-09-01 ', 27010899 956, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00 ', 'test2', 'zichen', 0, 0, 0, NULL), (12, '012', 'zhou Zhilian management Center ', '123', '2017-08-29 ', '2017-09-01', 27011099 9 95,100 00, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2', 'zichen', 0, 0, 0, NULL ), (13, '013', 'gaoling union management Center', '2017013', '2017-08-29 ', '2017-09-01', 27011199 985, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2', 'zichen', 0, 0, 0, NULL), (14, '014', 'field management Center', '2017014', '2017-08-29 ', '2017-09-01', 27011299 949, 2012, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2', 'Zichen', 0, 0, 0, NULL), (15, '015', 'home County Management Center', '123', '2017-08-29 ', '2017-09-01 ', 2014 987, 200000,199, '2017-07-26 00:00:00', '2017-08-08 15:38:00 ', 'test2', 'zichen', 0, 0, 0, NULL), (16, '016', 'jintai credit union management Center', '2017016', '2017-08-29 ', '2017-09-01 ', 200000,199 957, 10000, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2', 'zichen', 0, 0, 0, NULL ), (17, '017', 'weibin credit union management Center', '2017 ', '2017-08-29', '2017-09-01 ', 2012 981, 2014, '2017-07-26 00:00:00', '2017-08-08 15:38:00 ', 'test2', 'zichen', 0, 0, 0, NULL), (18, '018', 'hangzhoudistrict Joint Management Center of Xianyang city ', '123 ', '2017-08-29 ', '2017-09-01', 2012 987, 2014, '2017-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2 ', 'zichen', 0, 0, 0, NULL), (19, '019', 'qindu district Joint Management Center of Xianyang city ', '123', '2017-08-29 ', '2017-09-01 ', 2014 979, 200000,199, '2 012-07-26 00:00:00 ', '2017-08-08 15:38:00', 'test2', 'zichen', 0, 0, 0, NULL); the requirements are as follows: the jgmc field values in the table records must be assigned to their respective jgjc 2. solution: [SQL] update frjg set frjg. jgjc = (select jgmc from frjg f where f. id = frjg. id) where 1 executes the SQL command and reports an error. The error message is [SQL] #1093-You can't specify target table 'frjg' for update in FROM clause. You must create an intermediate table, the content of the intermediate table is exactly the same as that of the frjg table. Then, modify the frjg table. The intermediate and frjg tables have a "primary-foreign key relationship" (This relationship does not exist ): [SQL] create table tmp as (select * FROM frjg WHERE 1); update frjg SET jgjc = (SELECT jgmc FROM tmp WHERE frjg. id = tmp. id) WHERE 1; drop table tmp;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.