Jump to content

[SOLVED] MYSQL puzzle of the day


drranch

Recommended Posts

I'm working on a query that will pull appointment information from four different tables based on a BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)

 

AND

 

then populate the appointment information in an email script set up through cron

 

However,

there will be times that some of the tables will have several appointments and some tables may not have any appointments for this date range

 

In addition,

this script will pull information for different users and email the appointments to the user who has appointments for the date range.

 

I was able to write and test the script for a single table, but I'm not sure how to incorporate the other three tables.

 

apptcron.jpg

Link to comment
Share on other sites

Use UNION.

SELECT userid, app_date, app_description FROM table1 WHERE app_date BETWEEN ...
UNION
SELECT userid, app_date, app_description FROM table2 WHERE app_date BETWEEN ...
UNION
SELECT userid, app_date, app_description FROM table3 WHERE app_date BETWEEN ...
UNION
SELECT userid, app_date, app_description FROM table4 WHERE app_date BETWEEN ...
ORDER BY userid, appdate

 

NOTE: structure of rows returned by each SELECT must be the same.

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.