您的位置:首页 > 数据库 > MySQL

mysql 将select查询的值赋给update set语句中

2015-04-08 10:45 651 查看
表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';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql