Cita:
La vista es para que haga un listado de foros que tengo en una tabla, y consulte mediante la funcion Ultimo_Post si tiene algun post insertado o no, en el caso de que lo tenga muestra el campo.CREATE ALGORITHM=UNDEFINED
DEFINER=`mda`@`localhost` SQL SECURITY
DEFINER VIEW `vista_indice_foros` AS
select
`foro`.`titulo` AS `titulo`,
`Total_Posts`(`foro`.`id`) AS `contador`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `Ultimo_Post`(`foro`.`id`) else _utf8'' end) AS `ultimo_post`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `Usuario`(`post`.`id_usuario`) else _utf8'' end) AS `usuario`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `post`.`titulo` else _utf8'' end) AS `titulo_post`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `post`.`titulo_url` else _utf8'' end) AS `titulo_url_post`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `post`.`fecha` else _utf8'' end) AS `fecha_post`
from ((`foros` `foro` join `foros_posts` `post`) join `foros_categorias` `cat`)
where (((`foro`.`id` = `post`.`id_foro`) or (`Total_Posts`(`foro`.`id`) = 0)) and (`cat`.`id` = `foro`.`id_categoria`)) group by `foro`.`id`;
DEFINER=`mda`@`localhost` SQL SECURITY
DEFINER VIEW `vista_indice_foros` AS
select
`foro`.`titulo` AS `titulo`,
`Total_Posts`(`foro`.`id`) AS `contador`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `Ultimo_Post`(`foro`.`id`) else _utf8'' end) AS `ultimo_post`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `Usuario`(`post`.`id_usuario`) else _utf8'' end) AS `usuario`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `post`.`titulo` else _utf8'' end) AS `titulo_post`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `post`.`titulo_url` else _utf8'' end) AS `titulo_url_post`,
(case when (`Ultimo_Post`(`foro`.`id`) is not null) then `post`.`fecha` else _utf8'' end) AS `fecha_post`
from ((`foros` `foro` join `foros_posts` `post`) join `foros_categorias` `cat`)
where (((`foro`.`id` = `post`.`id_foro`) or (`Total_Posts`(`foro`.`id`) = 0)) and (`cat`.`id` = `foro`.`id_categoria`)) group by `foro`.`id`;
El problema es como llama a la misma funcion varias veces, creo que la relentiza un poco bastante, y la verdad que no me convence mucho llamar a la misma funcion tantas veces para sacar siempre lo mismo.
Igual hay un metodo más simple, pero no lo conozco.
A ver si alguien me ayuda.
Saludos,