I have 2 tables. table1 has primary records. table2 is slave table having multiple entries for table1.id. Some of the entries could be blank.
First if table2.data is set AND date is not past, then I have to get that record when I do a join of 2 tables. If there is no record with table2.data having not null value and date is not past, then fetch last updated record from table2, having table2.data IS NULL.
I need a single query to fetch NOT NULL or NULL record.
Table1
id name date
1 Abc 2013-12-09
2 Test 2014-12-09
3 Xyz 2012-02-10
Table2
id user_id data
1 1 test
2 1 NULL
3 2 NULL
4 3 blah blah.....
If I join 2 tables my result should be like, when I pass user_id = 1 and comparing date as today's date
Result
id user_id data
1 1 NULL
If I join 2 tables my result should be like, when I pass user_id = 2
Result
id user_id data
1 2 NULL
then fetch last updated record from table2: what defines the last update intable2?