I have this table in my database in oracle9i:
CREATE TABLE involved_in
(
rid number,
aid number NOT NULL,
fid number NOT NULL,
role varchar(80),
note varchar(80),
job varchar(35),
PRIMARY KEY(rid),
FOREIGN KEY(fid) REFERENCES production(pr_id),
FOREIGN KEY(aid) REFERENCES person(pid)
);
Which contains data about actors (aid) who worked in films (fid).
What I want to do is similar to working out the Bacon number
Except my kevin bacon is known for having the aid 517635.
I have no clue as to how to work out (only using SQL statements) the number of actors I have to connect a given actor (by another aid) with to find a connection to 517635.
The result of the query would be either a list of all the actors the given actor has to connect to get to my guy or just a number.
For that I thought I'd have to get first all the actors 517635 has worked with and those would have a 1 as a result for having worked directly with him. The table is not too big but big enough to make that inviable.
Examples, let's say Brad Pitt is my 517635. He worked with Angelina Jolie in Mr. And Mrs Smith, that would make her number 1. If Brad Pitt has never worked in any movie with Bruce Willis (let's say that's the case) but Angelina Jolie has been in one with him then Bruce Willis' number with respect to Brad Pitt would be 2.
In my query if the given number was Angelina's the result would be: "Brad Pitt 1" or simply "1" If the given number was Willis' the result would be: "Angelina Jolie Brad Pitt 2" or "2" Example of what is in the table:
INSERT INTO involved_in(rid, aid, fid, role, note, job) VALUES(1, 33, 1584953, 'Himself', 'NULL', 'actor');
INSERT INTO involved_in(rid, aid, fid, role, note, job) VALUES(2, 1135, 1999660, 'Himself', 'NULL', 'actor');
INSERT INTO involved_in(rid, aid, fid, role, note, job) VALUES(3, 1135, 2465724, 'Himself', 'NULL', 'actor');
INSERT INTO involved_in(rid, aid, fid, role, note, job) VALUES(4, 6003, 2387806, 'Himself', '(archive footage)', 'actor');
INSERT INTO involved_in(rid, aid, fid, role, note, job) VALUES(5, 13011, 1935123, 'Himself', 'NULL', 'actor');
I have nothing in my mind, I'm completely new to SQL and all I can think of leads to infinite loops with a variable to count the number of loops. Any ideas as to where to begin and, with luck, end?