grigzie Posted June 8, 2009 Share Posted June 8, 2009 I'm having difficulty running a mySQL query. I want to display the results from 2 different tables and displayed them depending on the age of the record entry. I can get all the entries from both tables to display EXCEPT FOR the latest entry (no matter which table it comes from). This problem doesn't happen if I change the ORDER BY so that it ascends. The code is below: $sql="(SELECT qcalendar.id, qcalendar.short_desc, qcalendar.long_desc, qcalendar.date_created AS date_created, qcalendar.date_start, users.user_id, users.user_fname, users.user_sname, qcalendar_category.category_name FROM users JOIN qcalendar ON users.user_id = qcalendar.created_by JOIN qcalendar_category ON qcalendar.category_id = qcalendar_category.id) UNION ALL (SELECT email_archive.email_archive_id, email_archive.email_archive_subject, email_archive.email_archive_body, email_archive.date_created AS date_created, '' AS c1, '' AS c2, '' AS c3, '' AS c4, '' AS c5 FROM email_archive) ORDER BY date_created DESC LIMIT 10"; I've tried removing all the JOINS and the dummy columns so that I had an equal number of columns which have the same format - yet I still get the same problem. Can you help, please? Link to comment https://forums.phpfreaks.com/topic/161360-problems-with-union-last-entry-vanishes/ Share on other sites More sharing options...
fenway Posted June 9, 2009 Share Posted June 9, 2009 I find that hard to believe... does each individual select return the expected results? Link to comment https://forums.phpfreaks.com/topic/161360-problems-with-union-last-entry-vanishes/#findComment-852041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.