I'm doing a project using JSF 2 and I have a particularly complicated query that does movie suggestions. I tried to put it as a named query and the compiler told me there was an error and I honestly have no idea where to look
SELECT M.*
FROM Account A,
Movie M,
Orders O,
Rental R,
(SELECT Acc.Id
FROM Account Acc,
(SELECT COUNT(*) AS c,
Acc.Id
FROM Account Acc,
(SELECT M.*
FROM Account A,
Rental R,
Orders O,
Movie M
WHERE A.Id=R.AccountId
AND R.MovieId=M.Id
AND R.OrderId=O.Id
AND A.Id=:id) AS a
INNER JOIN
(SELECT M.*,
A.Id AS AccountId
FROM Account A,
Rental R,
Orders O,
Movie M
WHERE A.Id=R.AccountId
AND R.MovieId=M.Id
AND R.OrderId=O.Id
AND A.Id<>:id) AS b USING (Id,Name,TYPE,Rating,DistrFee,NumCopies)
WHERE Acc.Id = b.AccountId ) AS COUNT
WHERE COUNT.c>0
AND COUNT.Id = Acc.Id) AS SimilarAccount
WHERE A.Id=R.AccountId
AND R.MovieId=M.Id
AND R.OrderId=O.Id
AND A.Id=:id
AND M.Id NOT IN
(SELECT M.Id
FROM Account A,
Rental R,
Orders O,
Movie M
WHERE A.Id=R.AccountId
AND R.MovieId=M.Id
AND R.OrderId=O.Id
AND A.Id=SimilarAccount.Id)
Performance issues aside (the professor wanted movie suggestions to be done via MySQL), I am not sure the procedure for storing this query for repeated using. I would store the query as a view, but it has a parameter (it requires a parameter id for the user)
How would you suggest storing this query?