I have searched this site and others but cannot find any help with this problem. Maybe I am making this more difficult than necessary.
I have two tables as follows. I want to return all the information for each item but only the most recent data and include data from both tables
table 1: serviceRequestSubmission
sid customerID
1001 11111
1002 22222
1003 33333
1004 44444
1005 55555
table 2: serviceRequestHistory
historyID requestID statusUpdate
1 1001 Assigned
2 1002 Assigned
3 1003 Pending
4 1004 Delayed
5 1002 Pending
6 1002 Closed
I want to return:
sidID historyID statusUpdate
1001 1 Assigned
1002 6 Closed
1003 3 Pending
1004 4 Delayed
1005 - Submitted
I have tried the following code but it returns all the rows of data but I only want the most recent/highest historyID.
SELECT serviceRequestSubmissions.*, serviceRequestHistory.*
FROM serviceRequestSubmissions
LEFT JOIN serviceRequestHistory ON serviceRequestSubmissions.sid = serviceRequestHistory.requestID
ORDER BY serviceRequestSubmissions.sid DESC
Any help would be appreciated. Thank you!
TIMESTAMPin your database - Zain Farooq