mysql 將select查詢的值賦給update set語句中

表tenant_oper結構:

create table `tenant_oper` (
  `id` int(11) not null auto_increment, 
  `oper_name` varchar(255) not null,
  `oper_code` varchar(255) not null,
  `remark` varchar(512) default "",
  `menu_id` int default 0,
  primary key (`id`)
) engine=InnoDB default charset=utf8;

表tenant_menu結構:

create table `tenant_menu` (
  `id` int(11) not null auto_increment, 
  `menu_code` varchar(255) not null,
  `menu_name` varchar(255) not null,
  `menu_position` smallint not null,
  `menu_url` varchar(255) default "",
  `parent_id` int default 0,
  primary key (`id`)
) engine=InnoDB default charset=utf8;


sql語句:
update tenant_oper set oper_code = '5_4_1_1', menu_id = (select id from tenant_menu where menu_code = '5_4_1') where oper_code = '5_4_1';



發佈了35 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章