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语句:
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查询语句使用select.. for update导致的数据库死锁分析
- Mysql查询语句使用select.. for update导致的数据库死锁分析
- Mysql update语句赋值嵌套select,更新和查询同一张表,必须取别名;用例:更新指定游戏服务器最后启动记录的结束时间
- T-SQL(标准数据库查询语句) 在SQL Server 2008 下面的 Create、Update,Delete、Select
- mysql 之SQL语句--NSERT SELECT ON DUPLICATE KEY UPDATE的写法
- 单个select语句实现MySQL查询统计次数
- MySQL update && select ,update的同时select,和for update 语句说再见。
- mysql下使用update set from select
- MySQL IFNULL中可以有select语句;查询一个表中的数据,同时查看另一个表中是否有符合条件的额数据
- mysql SELECT FOR UPDATE语句使用示例
- Mysql update语句赋值嵌套select
- 单个select语句实现MySQL查询统计次数
- Mysql InnoDB中的查询事务模式与锁定select ..for update
- mysql SELECT FOR UPDATE语句使用示例
- php中使用mysql_stmt(预处理语句)来处理select查询结果
- mysql优化SELECT语句和其它查询
- 单个select语句实现MySQL查询统计次数
- 6,mysql查询语句,select查询
- mysql的查询select 语句
- mysql 各种级联查询后更新(update select).