I have two working MySQL views:
First view selects all rows from table portfolio which id’s are in table mural as well.
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `view_mural` AS
select
`portfolio`.`id` AS `id`,
`portfolio`.`customer_id` AS `customer_id`,
`portfolio`.`location_id` AS `location_id`,
`portfolio`.`title_text_id` AS `title_text_id`,
`portfolio`.`description_text_id` AS `description_text_id`,
`portfolio`.`started` AS `started`,
`portfolio`.`finished` AS `finished`,
from
`portfolio`
where
`portfolio`.`id` in (select
`mural`.`portfolio_id`
from
`mural`) WITH CASCADED CHECK OPTION
Second view selects rows from two tables: portfolio and mural.
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `view_mural` AS
select
`portfolio`.`id` AS `id`,
`portfolio`.`customer_id` AS `customer_id`,
`portfolio`.`location_id` AS `location_id`,
`portfolio`.`title_text_id` AS `title_text_id`,
`portfolio`.`description_text_id` AS `description_text_id`,
`portfolio`.`started` AS `started`,
`portfolio`.`finished` AS `finished`,
(select
`mural`.`width`
from
`mural`
where
`mural`.`portfolio_id`=`portfolio`.`id`) AS `mup`
from
`portfolio`
I can’t get, how to combine these into one view, to select table, with columns from both tables, which contains rows from table portfolio which id’s are in table mural as well.
When I add:
where
`portfolio`.`id` in (select
`mural`.`portfolio_id`
from
`mural`) WITH CASCADED CHECK OPTION
to the very end of my second view it shows me an error:
Apply changes to view_mural Error 1368: CHECK OPTION on non-updatable view 'view_mural' SQL Statement: CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = `root`@`localhost` SQL SECURITY DEFINER VIEW `view_mural` AS select `portfolio`.`id` AS `id`, `portfolio`.`customer_id` AS `customer_id`, `portfolio`.`location_id` AS `location_id`, `portfolio`.`title_text_id` AS `title_text_id`, `portfolio`.`description_text_id` AS `description_text_id`, `portfolio`.`started` AS `started`, `portfolio`.`finished` AS `finished`, (select `mural`.`width` from `mural` where `mural`.`portfolio_id`=`portfolio`.`id`) AS `mup` from `portfolio` where `portfolio`.`id` in (select `mural`.`portfolio_id` from `mural`) WITH CASCADED CHECK OPTION Error when running failback script. Details follow. Error 1050: Table 'view_mural' already exists SQL Statement: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_mural` AS select `portfolio`.`id` AS `id`,`portfolio`.`customer_id` AS `customer_id`,`portfolio`.`location_id` AS `location_id`,`portfolio`.`title_text_id` AS `title_text_id`,`portfolio`.`description_text_id` AS `description_text_id`,`portfolio`.`started` AS `started`,`portfolio`.`finished` AS `finished`,(select `mural`.`width` from `mural` where ((`mural`.`portfolio_id` = `portfolio`.`id`) and `portfolio`.`id` in (select `mural`.`portfolio_id` from `mural`))) AS `mup` from `portfolio`
Could someone point me how can I do that?
Learn about SQL joins: