I'm running a query in MySQL with an INNER JOIN
that has a LIMIT
on the subquery
The problem is, that the LIMIT on the subquery is affecting the number of rows returned.
I want to select all rows from table 1 (tickets
) where the last row in ticket_updates
relevant (t.ticketnumber = tu.ticketnumber
) was not numeric in column contact_name
SELECT t.*
FROM tickets t
JOIN
( SELECT ticketnumber
FROM ticket_updates
WHERE type = 'update'
AND concat('', contact_name * 1) <> contact_name
ORDER
BY sequence DESC
LIMIT 1
) tu
ON t.ticketnumber = tu.ticketnumber
WHERE t.status <> 'Completed'
AND LOWER(t.department) = 'support';
But the results shown just return the 1 row
There are multiple rows in ticket_updates
that relate to each row in tickets
based on tickets.ticketnumber =
ticket_updates.ticketnumber`
the contact_name
column can either be a string or integer. I picked up the concat('', contact_name * 1) <> contact_name
from another SO Post which tells me whether the value is numeric or not.
So I want to pick up the latest row (ORDER BY sequence DESC
) in ticket_updates
for each row in tickets
and see whether contact_name
is not numeric