Question

Here is my code,

Select CAST.first_name, CAST.last_name, `directors winning movies list`.castID, count(*) AwardsWon
From `directors winning movies list`, CAST  
WHERE `directors winning movies list`.castID = CAST.castID
Group By `directors winning movies list`.castID
Having count(*)
    = (Select Max(cnt)
       From (Select count(*) cnt
             From `directors winning movies list`
             Group By `directors winning movies list`.castID) z)

The query itself executes correctly, but when I try and create a view and save this, I get the error #1349 view's select clause contains a subquery in the from clause. Does anyone know how to work around this?

Was it helpful?

Solution

MySQL doesn't allow to create a view with subquery. The possible workaround would be to create separate view for each subquery.

For example:

CREATE VIEW movies_view AS
SELECT COUNT(*) cnt
             FROM `directors winning movies list`
             GROUP BY `directors winning movies list`.castID) z)

CREATE VIEW movies_view_count AS
SELECT MAX(cnt) from movies_view

Call the movies_view_count in your main query and it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top