I apologize for the maybe stupid question. But I can't get a handle on it.
My postgres database has two tables with report dates. How can I check if the last report dates are the same?
I have tried:
select max (report_date)
from tba900_rephistory;
CASE
WHEN EXISTS (select max(reportdate) from t_data
THEN 'EXISTS'
ELSE 'missing'
END
But, it works every once in a while. SQL is not my strong suit, but I couldn't find anything to google.
In fact, I do it through psycopg2 in python. Maybe there are some tricks?
CodePudding user response:
You may use this query:
SELECT CASE WHEN (SELECT MAX(report_date) FROM tba900_rephistory) =
(SELECT MAX(reportdate) FROM t_data)
THEN 'exists' ELSE 'missing' END AS status;