2012-12-13 64 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

相關問題