I am returning records if today is more than x days from lastdate or I have previously specified a next date and that date is today. Here's my query
"select f.*, lastdate, nextdate from" & _ "(" & _ " SELECT f.*, lastdate, nextdate" & _ " FROM firms f" & _ " LEFT JOIN" & _ " (SELECT firm_ID, MAX(contacted) AS lastdate, MAX(arranged) AS nextdate FROM calls group by firm_id) c" & _ " ON c.firm_id = f.id" & _ " Where (julianday(current_date) - julianday(lastdate) > 6)" & _ " OR lastdate IS NULL" & _ " OR (julianday(current_date) = julianday(nextdate))" & _ " OR nextdate IS NULL" & _ ") f where f.status = 'ok'" I have modified my program to have next time (not shown) as well as next date What I'd to know is... How do I order results firstly by earlest non-null/empty string next time (ALL DAYS HERE WILL BE TODAY) order and then BY earliest non-null/empty string nextdate order so... I end up with a list of records in call time order followed by a list of records beginning with the one called longest ago. I hope that makes sense. BTW Sorry if I haven't thanked you for helping me before. I do get emails from the mailing list but...they're never mine or answers to mine. I'm just going to check the archives instead so just to let you know...I'm ALWAYS appreciative of all help I get!!! Thank you in anticipation _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users