Please find the fiddle here
Fiddle
My requirement is I need to display the latest record from 3rd table if exists based on first table ID and second table ID, if not I would like to display the latest record from second table. I have given the sample tables and the query I have written but i am not getting the actual result as per my need so some one can help me