PDOException Object
(
    [message:protected] => SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION
( SELECT
'emalu-store' as website,
(80000000 + `main_table`.id) as fgki' at line 1
    [string:Exception:private] => 
    [code:protected] => 42000
    [file:protected] => /var/www/mistermenuiserie.com/www/releases/20161003/lib/Zend/Db/Statement/Pdo.php
    [line:protected] => 228
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/lib/Zend/Db/Statement/Pdo.php
                    [line] => 228
                    [function] => execute
                    [class] => PDOStatement
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

            [1] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/lib/Varien/Db/Statement/Pdo/Mysql.php
                    [line] => 110
                    [function] => _execute
                    [class] => Zend_Db_Statement_Pdo
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

            [2] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/core/Zend/Db/Statement.php
                    [line] => 291
                    [function] => _execute
                    [class] => Varien_Db_Statement_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

            [3] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/lib/Zend/Db/Adapter/Abstract.php
                    [line] => 480
                    [function] => execute
                    [class] => Zend_Db_Statement
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

            [4] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/lib/Zend/Db/Adapter/Pdo/Abstract.php
                    [line] => 238
                    [function] => query
                    [class] => Zend_Db_Adapter_Abstract
                    [type] => ->
                    [args] => Array
                        (
                            [0] => UNION
( SELECT
'emalu-store' as website,
(80000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM emalustore_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN emalustore_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN emalustore_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join emalustore_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join emalustore_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
                            [1] => Array
                                (
                                )

                        )

                )

            [5] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/lib/Varien/Db/Adapter/Pdo/Mysql.php
                    [line] => 428
                    [function] => query
                    [class] => Zend_Db_Adapter_Pdo_Abstract
                    [type] => ->
                    [args] => Array
                        (
                            [0] => UNION
( SELECT
'emalu-store' as website,
(80000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM emalustore_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN emalustore_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN emalustore_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join emalustore_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join emalustore_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
                            [1] => Array
                                (
                                )

                        )

                )

            [6] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/lib/Varien/Db/Adapter/Pdo/Mysql.php
                    [line] => 347
                    [function] => query
                    [class] => Varien_Db_Adapter_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => UNION
( SELECT
'emalu-store' as website,
(80000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM emalustore_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN emalustore_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN emalustore_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join emalustore_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join emalustore_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
                        )

                )

            [7] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/lib/Varien/Db/Adapter/Pdo/Mysql.php
                    [line] => 617
                    [function] => raw_query
                    [class] => Varien_Db_Adapter_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => UNION
( SELECT
'emalu-store' as website,
(80000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM emalustore_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN emalustore_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN emalustore_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join emalustore_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join emalustore_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
                        )

                )

            [8] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/lib/Varien/Db/Adapter/Pdo/Mysql.php
                    [line] => 599
                    [function] => multi_query
                    [class] => Varien_Db_Adapter_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => drop view if exists aw_hdu3_merge_website;
create view aw_hdu3_merge_website as
( SELECT
'telecommandeonline' as website,
(10000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM telecmdonline_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN telecmdonline_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM telecmdonline_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN telecmdonline_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM telecmdonline_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN telecmdonline_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN telecmdonline_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join telecmdonline_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join telecmdonline_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'motorisationplus' as website,
(20000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM motorisationplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN motorisationplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM motorisationplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN motorisationplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM motorisationplus_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN motorisationplus_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN motorisationplus_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join motorisationplus_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join motorisationplus_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'labelhabitation' as website,
(30000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM labelhabitation_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN labelhabitation_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM labelhabitation_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN labelhabitation_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM labelhabitation_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN labelhabitation_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN labelhabitation_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join labelhabitation_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join labelhabitation_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'mistermenuiserie' as website,
(40000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM mistermenuiserie_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN mistermenuiserie_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM mistermenuiserie_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN mistermenuiserie_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM mistermenuiserie_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN mistermenuiserie_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN mistermenuiserie_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join mistermenuiserie_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join mistermenuiserie_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'radiateurplus' as website,
(50000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM radiateurplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN radiateurplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM radiateurplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN radiateurplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM radiateurplus_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN radiateurplus_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN radiateurplus_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join radiateurplus_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join radiateurplus_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'coffrefortplus' as website,
(60000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM coffrefortplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN coffrefortplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM coffrefortplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN coffrefortplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM coffrefortplus_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN coffrefortplus_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN coffrefortplus_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join coffrefortplus_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join coffrefortplus_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'poeleaboismaison' as website,
(70000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM poeleaboismaison_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN poeleaboismaison_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM poeleaboismaison_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN poeleaboismaison_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM poeleaboismaison_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN poeleaboismaison_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN poeleaboismaison_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join poeleaboismaison_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join poeleaboismaison_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status );
UNION
( SELECT
'emalu-store' as website,
(80000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM emalustore_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN emalustore_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN emalustore_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join emalustore_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join emalustore_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status );
                        )

                )

            [9] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 933
                    [function] => multiQuery
                    [class] => Varien_Db_Adapter_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => drop view if exists aw_hdu3_merge_website;
create view aw_hdu3_merge_website as
( SELECT
'telecommandeonline' as website,
(10000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM telecmdonline_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN telecmdonline_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM telecmdonline_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN telecmdonline_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM telecmdonline_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN telecmdonline_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN telecmdonline_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join telecmdonline_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join telecmdonline_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'motorisationplus' as website,
(20000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM motorisationplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN motorisationplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM motorisationplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN motorisationplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM motorisationplus_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN motorisationplus_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN motorisationplus_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join motorisationplus_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join motorisationplus_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'labelhabitation' as website,
(30000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM labelhabitation_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN labelhabitation_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM labelhabitation_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN labelhabitation_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM labelhabitation_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN labelhabitation_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN labelhabitation_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join labelhabitation_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join labelhabitation_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'mistermenuiserie' as website,
(40000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM mistermenuiserie_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN mistermenuiserie_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM mistermenuiserie_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN mistermenuiserie_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM mistermenuiserie_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN mistermenuiserie_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN mistermenuiserie_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join mistermenuiserie_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join mistermenuiserie_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'radiateurplus' as website,
(50000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM radiateurplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN radiateurplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM radiateurplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN radiateurplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM radiateurplus_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN radiateurplus_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN radiateurplus_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join radiateurplus_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join radiateurplus_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'coffrefortplus' as website,
(60000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM coffrefortplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN coffrefortplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM coffrefortplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN coffrefortplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM coffrefortplus_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN coffrefortplus_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN coffrefortplus_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join coffrefortplus_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join coffrefortplus_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'poeleaboismaison' as website,
(70000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM poeleaboismaison_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN poeleaboismaison_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM poeleaboismaison_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN poeleaboismaison_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM poeleaboismaison_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN poeleaboismaison_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN poeleaboismaison_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join poeleaboismaison_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join poeleaboismaison_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status );
UNION
( SELECT
'emalu-store' as website,
(80000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM emalustore_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN emalustore_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN emalustore_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join emalustore_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join emalustore_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status );
                        )

                )

            [10] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/local/Labelhabitation/MergeTickets/sql/mergetickets_setup/mysql4-install-0.1.0.php
                    [line] => 77
                    [function] => run
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ->
                    [args] => Array
                        (
                            [0] => drop view if exists aw_hdu3_merge_website;
create view aw_hdu3_merge_website as
( SELECT
'telecommandeonline' as website,
(10000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM telecmdonline_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN telecmdonline_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM telecmdonline_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN telecmdonline_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM telecmdonline_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN telecmdonline_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN telecmdonline_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join telecmdonline_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join telecmdonline_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'motorisationplus' as website,
(20000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM motorisationplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN motorisationplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM motorisationplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN motorisationplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM motorisationplus_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN motorisationplus_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN motorisationplus_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join motorisationplus_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join motorisationplus_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'labelhabitation' as website,
(30000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM labelhabitation_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN labelhabitation_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM labelhabitation_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN labelhabitation_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM labelhabitation_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN labelhabitation_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN labelhabitation_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join labelhabitation_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join labelhabitation_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'mistermenuiserie' as website,
(40000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM mistermenuiserie_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN mistermenuiserie_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM mistermenuiserie_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN mistermenuiserie_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM mistermenuiserie_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN mistermenuiserie_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN mistermenuiserie_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join mistermenuiserie_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join mistermenuiserie_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'radiateurplus' as website,
(50000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM radiateurplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN radiateurplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM radiateurplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN radiateurplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM radiateurplus_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN radiateurplus_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN radiateurplus_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join radiateurplus_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join radiateurplus_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'coffrefortplus' as website,
(60000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM coffrefortplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN coffrefortplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM coffrefortplus_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN coffrefortplus_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM coffrefortplus_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN coffrefortplus_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN coffrefortplus_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join coffrefortplus_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join coffrefortplus_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status )
UNION
( SELECT
'poeleaboismaison' as website,
(70000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM poeleaboismaison_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN poeleaboismaison_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM poeleaboismaison_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN poeleaboismaison_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM poeleaboismaison_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN poeleaboismaison_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN poeleaboismaison_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join poeleaboismaison_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join poeleaboismaison_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status );
UNION
( SELECT
'emalu-store' as website,
(80000000 + `main_table`.id) as fgkid,
`main_table`.id,
`main_table`.id as idticket,
`main_table`.uid,
`d_dm`.id as idcategory,
`d_dm`.title as category,
`d_ag`.name as agent,
`main_table`.subject,
`main_table`.order_increment_id as commande,
t_pr.value as priority,
main_table.status as idstatus,
t_st.value as status,
`main_table`.is_locked,
(SELECT IFNULL(COUNT(t_tm.id), 0)
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id ORDER BY t_th.created_at DESC) as messages_count,
(SELECT IFNULL(MAX(t_th.created_at), '0000-00-00')
            FROM emalustore_3.aw_hdu3_ticket_message as t_tm
            LEFT JOIN emalustore_3.aw_hdu3_ticket_history as t_th ON t_tm.history_id = t_th.id AND t_th.event_type = 4
            WHERE t_tm.ticket_id = main_table.id
            GROUP BY t_tm.ticket_id) as last_message_date,
`main_table`.created_at

FROM emalustore_3.`aw_hdu3_ticket` AS `main_table`
LEFT JOIN emalustore_3.`aw_hdu3_department` as d_dm on `d_dm`.`id` = `main_table`.`department_id`
LEFT JOIN emalustore_3.`aw_hdu3_department_agent` as d_ag on `d_ag`.id
 = `main_table`.`department_agent_id`
 left join emalustore_3.aw_hdu3_ticket_priority_label as t_pr on t_pr.id = `main_table`.priority
 left join emalustore_3.aw_hdu3_ticket_status_label as t_st on t_st.id = `main_table`.status );
                        )

                )

            [11] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 624
                    [args] => Array
                        (
                            [0] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/local/Labelhabitation/MergeTickets/sql/mergetickets_setup/mysql4-install-0.1.0.php
                        )

                    [function] => include
                )

            [12] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 421
                    [function] => _modifyResourceDb
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ->
                    [args] => Array
                        (
                            [0] => install
                            [1] => 
                            [2] => 0.1.0
                        )

                )

            [13] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 327
                    [function] => _installResourceDb
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ->
                    [args] => Array
                        (
                            [0] => 0.1.0
                        )

                )

            [14] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 235
                    [function] => applyUpdates
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ->
                    [args] => Array
                        (
                        )

                )

            [15] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/core/Mage/Core/Model/App.php
                    [line] => 417
                    [function] => applyAllUpdates
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ::
                    [args] => Array
                        (
                        )

                )

            [16] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/code/core/Mage/Core/Model/App.php
                    [line] => 343
                    [function] => _initModules
                    [class] => Mage_Core_Model_App
                    [type] => ->
                    [args] => Array
                        (
                        )

                )

            [17] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/releases/20161003/app/Mage.php
                    [line] => 684
                    [function] => run
                    [class] => Mage_Core_Model_App
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                    [scope_code] => base
                                    [scope_type] => website
                                    [options] => Array
                                        (
                                        )

                                )

                        )

                )

            [18] => Array
                (
                    [file] => /var/www/mistermenuiserie.com/www/shared/config/index.php
                    [line] => 170
                    [function] => run
                    [class] => Mage
                    [type] => ::
                    [args] => Array
                        (
                            [0] => base
                            [1] => website
                        )

                )

        )

    [previous:Exception:private] => 
    [errorInfo] => Array
        (
            [0] => 42000
            [1] => 1064
            [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION
( SELECT
'emalu-store' as website,
(80000000 + `main_table`.id) as fgki' at line 1
        )

)