首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql百万数据查询 用什么代替in,该如何处理

2012-03-09 
mysql百万数据查询用什么代替inSQL codecreate temporary table tmp_c select IMG_ID from img_entry_one

mysql百万数据查询 用什么代替in

SQL code
create temporary table tmp_c select IMG_ID from img_entry_one where STATU_ID=1 limit 0,10;update img_entry_one set STATU_ID=2,USER_ID='c' where IMG_ID in (select IMG_ID from tmp_c);select IMG_PATH from imgs inner join tmp_c on imgs.IMG_ID=tmp_c.IMG_ID ;DROP TABLE tmp_c;


where IMG_ID in (select IMG_ID from tmp_c);
怎么写好,用in太慢了。

[解决办法]
update img_entry_one a inner join tmp_c b on a.IMG_ID=b.IMG_ID
set STATU_ID=2,USER_ID='c' 

在img_entry_one、tmp_c 表IMG_ID上建立索引
[解决办法]
mysql的in嵌套select语句优化的不好 要避免


改成表连接即可
SQL code
update  img_entry_one A,tmp_c Bset STATU_ID=2,USER_ID='c'where A.IMG_ID=B.IMG_ID 

热点排行