With information gathered from a question I posted 3 weeks ago, I made the following query for my movie database:
The query shows how many movies a nation has listed (including an average score). The problem is that a movie might have several production nations and this query counts all of them. Instead, I want the query to just use the main nation. I can't figure it out by myself, so here I am again.
I think the answer lies in the linked table where each entry has a unique ID (LinkFilmNation ID). The table has three colums:
For each 'Film ID', the query should only select the 'LinkFilmNation ID' that has the lowest number (the lowest number is the first in line and represents the main production nation).
A simplified example in layman's terms:
According to the site IMDb.com, the movie The Matrix (Film ID = 25) has two production nations, the USA and Australia. For this movie the LinkFilmNation ID's are 1051 and 1052. With the current query I would get the following (simplified):
Nation ID Nation Total
53 USA 1
12 Australia 1
What a want is that each movie (aka Film ID) counts only one time; therefore the query should only use the entry marked 1051 and discard the other entry that goes with the same Film ID (1052). This would result in:
Nation ID Nation Total
53 USA 1
And this is what I want.
I hope I made myself clear enough. Thank you. Margie
Code:
SELECT Nation.Nation, LinkFilmNation.[Nation ID], Count(*) AS Total, Avg(Film.[Score]) AS [Average Score] FROM Film INNER JOIN Nation INNER JOIN LinkFilmNation ON Nation.[Nation ID] = LinkFilmNation.[Nation ID]) ON Film.[Film ID] = LinkFilmNation.[Film ID] GROUP BY Nation.Nation, LinkFilmNation.[Nation ID], Film.Status, Film.Ok HAVING (((Film.Status)="Seen") AND ((Film.Ok)=Yes)) ORDER BY Count(*) DESC;
I think the answer lies in the linked table where each entry has a unique ID (LinkFilmNation ID). The table has three colums:
Code:
SELECT LinkFilmNation.[LinkFilmNation ID], LinkFilmNation.[Film ID], LinkFilmNation.[Nation ID] FROM LinkFilmNation;
A simplified example in layman's terms:
According to the site IMDb.com, the movie The Matrix (Film ID = 25) has two production nations, the USA and Australia. For this movie the LinkFilmNation ID's are 1051 and 1052. With the current query I would get the following (simplified):
Nation ID Nation Total
53 USA 1
12 Australia 1
What a want is that each movie (aka Film ID) counts only one time; therefore the query should only use the entry marked 1051 and discard the other entry that goes with the same Film ID (1052). This would result in:
Nation ID Nation Total
53 USA 1
And this is what I want.
I hope I made myself clear enough. Thank you. Margie





Comment