new StringBuffer(); sb.append("SELECT picture_id, SUM(access_count) AS count_sum FROM count_log"); sb.append(" WHERE picture_id IN ("); sb.append(" SELECT id FROM picture"); sb.append(" ) "); sb.append(" GROUP BY picture_id"); sb.append(" ORDER BY count_sum DESC, picture_id ASC"); (後略) • 不思議かつ無駄なサブクエリとの組み合わせ方をしている • picture テーブルと count_log テーブルを JOIN すれば一発 ◦ 方法①なら picture に count_log を LEFT JOIN & GROUP BY & COUNT(*) ◦ 方法②なら picture と count_log を 1:1 で INNER JOIN