これらの列を持つテーブルがあります:
id | series_id | season_id | episode_id | title | type ...
series_id
一意のwhereseason_id
とepisode_id
are maxを持つ行を取得したいと思います。
1つの解決策はこれを行うことです:
SELECT t1.*
FROM YourTable AS t1
INNER JOIN
(
SELECT
series_id,
MAX(season_id) AS MAxSeasonId,
MAX(Episode_id) AS MAXEpisodeID
FROM yourTable
GROUP BY series_id
) AS t2 ON t1.series_id = t2.series_id
AND t1.season_id = t2.MaxSeasonId
AND t1.episode_id = t2.MaxEpisode_id;
SELECT *
FROM TableName t1
WHERE EXISTS (
SELECT 1
FROM t2
WHERE t1.series_id = t2.series_id
HAVING MAX(t2.season_id) = t1.season_id
AND MAX(t2.episode_id ) = t1.episode_id
)
これを試して..
SELECT * FROM TABLE
HAVING MAX(season_id) AND MAX(episode_id)
GROUP BY series_id
:)