42 lines
1009 B
MySQL
42 lines
1009 B
MySQL
|
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||
|
SQL SECURITY DEFINER
|
||
|
VIEW `vn`.`clientPhoneBook`
|
||
|
AS SELECT `c`.`id` AS `clientFk`,
|
||
|
trim(`c`.`phone`) AS `phone`
|
||
|
FROM `vn`.`client` `c`
|
||
|
WHERE `c`.`phone` <> 0
|
||
|
AND `c`.`isActive` <> 0
|
||
|
UNION
|
||
|
SELECT `c`.`id` AS `clientFk`,
|
||
|
trim(`c`.`mobile`) AS `phone`
|
||
|
FROM `vn`.`client` `c`
|
||
|
WHERE `c`.`mobile` <> 0
|
||
|
AND `c`.`isActive` <> 0
|
||
|
UNION
|
||
|
SELECT `a`.`clientFk` AS `clientFk`,
|
||
|
trim(`a`.`phone`) AS `phone`
|
||
|
FROM (
|
||
|
`vn`.`address` `a`
|
||
|
JOIN `vn`.`client` `c` ON(`c`.`id` = `a`.`clientFk`)
|
||
|
)
|
||
|
WHERE `a`.`phone` <> 0
|
||
|
AND `c`.`isActive` <> 0
|
||
|
UNION
|
||
|
SELECT `a`.`clientFk` AS `clientFk`,
|
||
|
trim(`a`.`mobile`) AS `phone`
|
||
|
FROM (
|
||
|
`vn`.`address` `a`
|
||
|
JOIN `vn`.`client` `c` ON(`c`.`id` = `a`.`clientFk`)
|
||
|
)
|
||
|
WHERE `a`.`mobile` <> 0
|
||
|
AND `c`.`isActive` <> 0
|
||
|
UNION
|
||
|
SELECT `cc`.`clientFk` AS `clientFk`,
|
||
|
trim(`cc`.`phone`) AS `phone`
|
||
|
FROM (
|
||
|
`vn`.`clientContact` `cc`
|
||
|
LEFT JOIN `vn`.`client` `c` ON(`c`.`id` = `cc`.`clientFk`)
|
||
|
)
|
||
|
WHERE `c`.`phone` <> 0
|
||
|
AND `c`.`isActive` <> 0
|