Good day!
Please help me to fix my query, it is returning double data when I run it thru SQL BOX please
see the screenshot for reference.
Code: Select all
SELECT concat(u.first_name," ",u.last_name) owner,
ts.name state,
t.tn ticket_number,
t.customer_user_id customer_id,
t.customer_id customer,
th.create_time start_time,
dfv1.value_text category,
a.a_body latest_update,
Coalesce((SELECT th2.create_time
FROM ticket_history th2
WHERE th2.history_type_id IN ( '1', '27' )
AND th2.ticket_id = th.ticket_id
AND th2.id > th.id
LIMIT 1), Now())
end_time,
TIMEDIFF(Coalesce(
(SELECT th2.create_time
FROM ticket_history th2
WHERE th2.history_type_id IN (
'1', '27' )
AND th2.ticket_id =
th.ticket_id
AND th2.id > th.id
LIMIT 1), Now()),th.create_time) time_range
FROM `ticket_history` th
LEFT JOIN users u
ON u.id=th.create_by
LEFT JOIN ticket_state ts
ON ts.id = th.state_id
LEFT JOIN ticket t
ON t.id=th.ticket_id
INNER JOIN dynamic_field_value dfv1
ON th.ticket_id = dfv1.object_id
INNER JOIN article a
ON a.ticket_id = t.id
WHERE th.history_type_id IN ( '1', '27' )
AND ts.id != '2'
AND dfv1.field_id =4
AND t.create_time
BETWEEN '2016-06-10 00:00:00' AND '2016-08-22 23:59:59'
ORDER BY t.id
please help me to fix it
