I have 2 tables properties and property_history structure some thing like that
proerties -
id | property_address | owner
1 | abc | xyz
2 | 123 | efg
property_history-
id | property_id | date1 | date2 | date3 | date4
1 | 1 | 2012-05-01 | 0000-00-00 | 2002-06-11 | 2006-06-11 |
2 | 1 | 2019-05-01 | 0000-00-00 | 2003-06-11 | 2007-06-11 |
3 | 1 | 0000-00-00 | 2011-06-11 | 2004-06-11 | 2011-06-11 |
4 | 1 | 0000-00-00 | 2020-01-31 | 2005-06-11 | 0000-00-11 |
I need to join these two table as
- All rows from properties table
- Only 1 row form property history with latest date from any of the date column as latest date for eg. latest date between( date1, date2, date3, date4) as latest_date as one column
- If property_history not have any row with respect property id then latest_date should be null