Jump to content

Problems with UNION - last entry vanishes!?!


grigzie

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.