mysql使用强制索引:
# mysql中使用强制索引 force index(索引名称)
select *from salaries force index(idx_emp_no) where emp_no = 10005
insert插入,存在则忽略:
insert ignore table values(....)
MySQL的UPDATE或DELETE中子查询不能为同一张表,可将查询结果再次SELECT,并且需要添加别名。
下面的写法会出错:
delete from titles_test where id
not in (select min(id) from titles_test group by emp_no);
修改后:
delete from titles_test where id not in
(select *from (select min(id) from titles_test group by emp_no) as t);