USE `vn`; CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = `root`@`%` SQL SECURITY DEFINER VIEW `vn`.`workerDepartment` AS SELECT `p`.`id_trabajador` AS `workerFk`, `d`.`id` AS `departmentFk` FROM (((`postgresql`.`person` `p` JOIN `postgresql`.`profile` `pr` ON ((`pr`.`person_id` = `p`.`person_id`))) LEFT JOIN (`postgresql`.`business` `b` LEFT JOIN `postgresql`.`business_labour` `bl` ON ((`b`.`business_id` = `bl`.`business_id`))) ON ((`pr`.`profile_id` = `b`.`client_id`))) JOIN `vn`.`department` `d` ON ((`d`.`id` = `bl`.`department_id`))) WHERE (ISNULL(`b`.`date_end`) OR (`b`.`date_end` > CURDATE()));