I need to get the datestamp of a specific type of status (say 160) -IF- it exists for the order, otherwise fallback to the date of status 110 (which should always be present).
A simple example of the datebase has been set up here:
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=078d09c494bdfd18374bdf81d61d19a5
Thanks to stackoverflow i did achieve it in sql using the following query:
select o.OrderId, coalesce(loadedTime.Date, pendingTime.Date) AS time_stamp
from [Order] o
Join OrderStatus pendingTime
on pendingTime.OrderId = o.OrderId
and pendingTime.Type = 110
Left join OrderStatus loadedTime
ON loadedTime.OrderId = o.OrderId
and loadedTime.Type = 160