drranch Posted December 29, 2007 Share Posted December 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83552-solved-mysql-puzzle-of-the-day/ Share on other sites More sharing options...
Barand Posted December 29, 2007 Share Posted December 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83552-solved-mysql-puzzle-of-the-day/#findComment-425191 Share on other sites More sharing options...
drranch Posted December 30, 2007 Author Share Posted December 30, 2007 Excellent! I learned a lot about union and I had to change a few of my tables so it would give up the results I was looking for. Thank you for your time and knowledge....VERY MUCH APPRECIATED! Quote Link to comment https://forums.phpfreaks.com/topic/83552-solved-mysql-puzzle-of-the-day/#findComment-426052 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.