1

Okay so I have the following table design for 'Movie':

movie_id
previous_part
title

Now when I have a Movie id, I want to get all previous and next parts of the movie, but when it's the last movie in a series, the previous_part column will be NULL. I would like a query with a movie_id input that can get all parts of a movie, considering it could be the last movie in a series or just any part in the series.

Edit: It is an SQL query that will be used in MSAcces, but I dont think that matters really. I will try to re-explain it simply: Movie has previous_part, which will be the same as the movie_id of another movie. For example:

Movie 1: movie_id: 1 previous_part: NULL title: "Example movie"

Movie 2: movie_id: 2 previous_part: 1 title "Example movie 2"

Movie 3: movie_id: 3 previous_part: 2 title "Example movie 3"

I want to get all 3 of these movies when you enter either one of the 3 id's. Maybe that clears up the question.

Edit2: I dont think this is a duplicatie question, in my case: when you select the first movie in a series, the previous_part column is NULL, and you want to get the other parts of the movie that come after. How do you do that?

Thomas
  • 21
  • 7
  • Are you using MySQL or MS Access? – Siyual Jan 11 '16 at 21:28
  • 2
    Please provide sample data and sample output. Description is not totally clear. – Alex Jan 11 '16 at 21:28
  • @Siyual, the question is tagged `mysql` – Alex Jan 11 '16 at 21:28
  • @AlexanderMP It is also tagged `ms-access` – Siyual Jan 11 '16 at 21:29
  • 2
    oh. I guess I had a `.First(t=>IsRDBMS(t))` moment (C# LINQ reference) – Alex Jan 11 '16 at 21:31
  • 1
    You're trying to traverse a linked list using SQL. That might make finding an answer easier. – zebediah49 Jan 11 '16 at 21:32
  • Every recursion must come to an end, whether it's because the last target id doesn't exist or because the last target id is NULL doesn't really matter. IMO your question isn't a duplicate (I voted unclear) because all the answers in the linked question are MySql specific. But since you didn't care to fix your tags... – Andre Jan 12 '16 at 18:13
  • Anyway, to have a chance to get your question reopened I suggest you add non-trivial sample data and sample output in **tabular** form. Use http://www.sensefulsolutions.com/2010/10/format-text-as-table.html --- Also, is there a limit to the number of movie parts? – Andre Jan 12 '16 at 18:14

0 Answers0