OK, so I'm working on a home theater system, and to display the list of TV series I have been selecting the first episode of the first season and displaying the associated information for just that episode, then you can drill down to others.
That way I can keep all the movies and all the TV shows in a single table which makes the playback functions much easier.
The problem is, some of the series I don't have the first episode in the database, and I want them to appear anyway, so I want to select the minimum season/series instead of the first.
I can't put MIN
in the select clause as then it only selects one series, and I can't put LEAST
in the WHERE
clause because it says it's only one element because of the way they're grouped, and I can't use LIMIT
because again then it will only select one series.
Is there a way to do this without multiple complicated subqueries?
Here's the query I'm using at the moment, the CASE
clause is to remove A/An/The from the series title for proper alphabetical order:
SELECT *, CASE when substring(series,1,4) = 'The ' then substring(series, 5)
when substring(series,1,3) = 'An ' then substring(series, 4)
when substring(series,1,2) = 'A ' then substring(series, 3)
else series END AS sorttitle
FROM Theater.Videos WHERE type='TV' and season=1 and episode=1 ORDER BY sorttitle ASC
And here's essentially what I want:
SELECT *, CASE when substring(series,1,4) = 'The ' then substring(series, 5)
when substring(series,1,3) = 'An ' then substring(series, 4)
when substring(series,1,2) = 'A ' then substring(series, 3)
else series END AS sorttitle
FROM Theater.Videos WHERE type='TV' and season=MIN(season) and episode=MIN(episode) ORDER BY sorttitle ASC