Trying to write a query that gives me all rows from samples, all matches (if any) from samples_pictures and the most recent record (if any) from samples_details. Thus, there are two left outer joins, but one of them retrieves only the most recent record.
What does not work:
SELECT samples.* , samples_pictures.SamplesPicID , CustomerName , date_out , date_returned , updated , samples_details.status as txn_status FROM samples LEFT OUTER JOIN ( SELECT Samples_Details_ID , samples_details.status as txn_status , MAX(updated) as MaxUpdated FROM samples_details GROUP BY Samples_Details_ID ) AS MaxTable ON MaxTable.SamplesID = samples.SamplesID LEFT OUTER JOIN samples_pictures ON samples.SamplesID = samples_pictures.SamplesID
Any help would be greatly appreciated!
source share