2012-12-13 32 views
0

该查询从两个单独的表中提取。 video_thumb_chosen有一个需要选择模式值的位置的缩略图列。有没有更快的方法来做组sql查询?

$query = "SELECT DISTINCT videos.VIDEOID, 
          videos.title, 
          (
          select video_thumb_chosen.thumb 
          from video_thumb_chosen 
          where video_thumb_chosen.videoid = videos.VIDEOID 
          group by video_thumb_chosen.thumb 
          order by count(video_thumb_chosen.thumb) desc limit 1 
         ) as thumb, 
          videos.rating, 
          videos.runtime, 
          videos.viewcount, 
          videos.public, 
          videos.time_added, 
          videos.HD 
      FROM videos,video_thumb_chosen 
      WHERE videos.active='1' 
      && videos.tube=0 
      && videos.categories <> 7 
      ORDER BY videos.last_viewed desc limit $config[max_viewing_now]"; 
+0

多一点点... – Jivan

+0

您正在使用什么数据库指定你的问题? –

+0

使用mysql(ADONewConnection)数据库 – user997101

回答

1

卸下from子句中的交叉连接将有助于:

FROM videos 

你是不是在外部查询使用video_thumb_chosen,所以没有理由将其列入。

也可能有其他优化。

鉴于你在MySQL中正在做什么,可能会解决这个问题。下面是该查询:

SELECT videos.VIDEOID, videos.title, 
     (select video_thumb_chosen.thumb 
     from video_thumb_chosen 
     where video_thumb_chosen.videoid = videos.VIDEOID 
     group by video_thumb_chosen.thumb 
     order by count(video_thumb_chosen.thumb) desc limit 1 
    ) as thumb, 
     videos.rating, videos.runtime, videos.viewcount, videos.public, videos.time_added, videos.HD 
FROM videos 
where videos.active='1' && videos.tube=0 && videos.categories <> 7 
ORDER BY videos.last_viewed 
desc limit $config[max_viewing_now]"; 
+0

感谢它工作得更快,但它仍然是一个蜗牛的步调与另一个2个查询类似于这一个在一个页面上。花一分钟时间加载。 – user997101

+0

道歉只是清除了我的浏览器数据并重新启动浏览器,它工作得很好。谢谢 – user997101

相关问题