Hello, I am trying to this my MYSQL rather than loading the whole stinking database to arrays to sort.
I have three tables personal, company and location. Each table has a field p_mwhen, c_mwhen, l_mwhen which contain a DATETIME value indicating the time of the last modification for that row.
The three tables together make up a "contact" consinsting of one record from each table.
I want to select the 5 mosty recently modified records.... I tried doing ORDER BY p_mwhen DESC, c_mwhen DESC, l_mwhen DESC but it only found the first 5 from personal, then company, then location ... it wasn't exactly what I wanted.
So I tried this query
"SELECT m_key, m_contact_key, m_empl_key, " .
" MAX(p.p_mwhen, c.c_mwhen, l.l_mwhen) as mod_date " .
"FROM contact_list.mycontacts as m, contact_list.personal as p, " .
" contact_list.company as c, contact_list.location as l " .
"WHERE m_empl_key = '$user_key' AND p.p_key=m.m_contact_key " .
" AND p.c_key=c.c_key " .
" AND p.l_key=l.l_key " .
"ORDER BY mod_date DESC " .
"LIMIT $limit"
And got this error:
You have an error in your SQL syntax near ' c.c_mwhen, l.l_mwhen) as mod_date FROM contact_list.mycontacts as m, contact_li' at line 1
So, that apparently won't work...
Any ideas?
Thanks 🙂 Nola