I have a query with several left joins and with last left join in which one I'm using sub query (because it has to be ordered) I need several columns to represent.
Query that I wrote:
SELECT pr.id, prs.requestStatus, prs.changeDate 
FROM `ho_port_phone_number_requests` pr
left join ho_port_phone_number_requests_rejection_reason rrr on rrr.id = 
pr.rejectionReasonId
left join ho_user u on u.userId = pr.csId
left join ho_customer c on c.id = pr.customerId
left JOIN 
(SELECT requestId, requestStatus, changeDate FROM 
ho_port_phone_number_request_status ORDER BY requestId DESC LIMIT 1) prs
ON prs.requestId = pr.id
I know that I can write two sub queries inside SELECT but then it's last much longer. The code that work but is slow:
SELECT pr.id,
(SELECT st.requestStatus FROM ho_port_phone_number_request_status st
WHERE st.requestId = pr.id ORDER BY requestId DESC LIMIT 1) as rStatus,
(SELECT st.changeDate FROM ho_port_phone_number_request_status st
WHERE st.requestId = pr.id ORDER BY requestId DESC LIMIT 1) as rDate
FROM `ho_port_phone_number_requests` pr
left join ho_port_phone_number_requests_rejection_reason rrr on rrr.id = 
pr.rejectionReasonId
left join ho_user u on u.userId = pr.csId
left join ho_customer c on c.id = pr.customerId
Any advice?
 
    