Reputation: 333
I am trying to get the last date between 3 columns (for each row) I found a solution in SQL server but apparently it can't be used in Bigquery
SELECT
ID,
(SELECT MAX(LastUpdateDate)
FROM (VALUES (UpdateByApp1Date),(UpdateByApp2Date),(UpdateByApp3Date)) AS UpdateDate(LastUpdateDate))
AS LastUpdateDate
FROM ##TestTable
Upvotes: 0
Views: 2381
Reputation: 172993
Consider below approach
select id, name,
greatest(UpdateByApp1Date, UpdateByApp2Date, UpdateByApp3Date) as LastUpdateDate
from TestTable
Upvotes: 3