Something like:
SELECT
th.name, th.ticket_id, max(th.create_time) FROM `ticket_history` th left join ticket_history_type tht on th.history_type_id =
tht.id where
tht.name = "StateUpdate" and (
th.name like "%\%\%new\%\%" OR
th.name like "%\%\%pending %\%\%") group by th.ticket_id
beyond that, you'll probably want to start by understanding SQL queries, present what you tried to do (optionally, show where you got that information from to try it) and then present error messages or reasons that the thing you tried to do on your own doesn't comply with the result you desired. Or hire someone.