I need help with a query. I have a nested query that pull from 2 tables with a union all. I want to combine the 2 record it pull, but the greater value of the 2 into 1 record. Or more like if it's NULL then use the other value from the other record.
See my query and example output.
SELECT X.ID, X.ORDER_ID, X.DATE, X.STATUS, X.ORDER_POLICYFROM ( SELECT ITEM_ID AS ID, ORDER_ID, TRANSACTION_DATE AS DATE, NULL AS STATUS, AS NULL ORDER_POLICY FROM SALES_ORDER WHERE UNION ALL SELECT ID, NULL AS ORDER_ID, NULL AS DATE, NULL AS STATUS, ORDER_POLICY FROM ITEMS ) XWHERE X.ID = '129892' AND ISNULL(NULLIF(X.ORDER_ID, ''), '' = 'SO12342'