mysql - Join with multiple conditions -


my entire query bit complex i'll try show need understand problem, i'm fetching tickets data base, displays title, creator, people in charge of ticket, , last updater, creator , people in charge find id in tickets_users.users_id , type 1 or 2 depending if creator of ticket or if in charge, title , informations of ticket table named tickets users id name etc it's users

so query looks that:

select tickets.id,     tickets.name,     group_concat(             case when tickets_users.type = 1                          concat(users.firstname, ' ', users.realname)             end) creator,     group_concat(             case when tickets_users.type = 1                          concat(tickets_users.users_id)             end) creator_id,     group_concat(             case when tickets_users.type = 2                          concat(users.firstname, ' ', users.realname)             end) in_charge,     group_concat(             case when tickets_users.type = 2                          concat(tickets_users.users_id)             end) in_charge_id,     tickets.date,     tickets.priority,     tickets.date_mod,     tickets.status,     tickets.users_id_lastupdater, max(case when tickets.users_id_lastupdater = users.id          concat(users.firstname, ' ', users.realname)      end) last_updater, tickets.content     tickets     join tickets_users on tickets_users.tickets_id = tickets.id     join users on users.id = tickets_users.users_id     tickets.id = ?"); 

my problem there join users on users.id = tickets_users.users_id works people in charge , creator, if not in charge reply or modify ticket not appear in "last modified by" because last_updater id in table tickets. tried join join users on (users.id = tickets_users.users_id , , glpi_tickets.users_id_lastupdater) didn't work. ideas?

on users.id in (tickets_users.users_id, tickets.last_updater) 

and

you'd need add test and users.id = tickets_users.users_id case statements

worked, eggyal!


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -