0

このクエリは、2 つの個別のテーブルから取得します。video_thumb_chosen には、モード値を選択する必要がある Thumbcolumn があります。

$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]"; 
4

1 に答える 1

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]"; 
于 2012-12-13T15:49:54.697 に答える