* revised, but still not solved…*
I want to combine data from two files but I am having trouble expressing the sort. I want to sort on either the CREATED date from the first file and the SHARED_DATE from the second file if it exists and it is larger.
file 1 : NODE
fields: CREATED, CHANGED
file 2 : SHARE_CONTENT
fields: SHARED_DATE , NODE (foreign key)
…
SELECT n.created, s.shared_date,
(CASE WHEN s.shared_date <> NULL
then s.shared_date
else n.created
END)
as lastshare
FROM node as n LEFT JOIN share_content as s on (s.nid=n.nid)
ORDER BY lastshare DESC
another possibility..
SELECT n.created, s.shared_date,
FROM node as n LEFT JOIN share_content as s on (s.nid=n.nid)
ORDER BY MAX(n.created, s.shared_date) DESC
except mySQL does not seem to like MAX(a,b)
Specifically note the IS NOT instead of <>. NULL is very, very special in SQL.