daiv Posted March 21, 2006 Share Posted March 21, 2006 Hi,I have a join between 3 tables that finds users that are active, their email address and their backup log for the previous day. I then send them an email with the information. this works fine with the code below[code]SELECT EmailNotify . * , FTPUsers.Firstname, FTPUsers.LastName, UserTable . *FROM EmailNotifyLEFT JOIN FTPUsers ON EmailNotify.Username = FTPUsers.UsernameLEFT JOIN UserTable ON EmailNotify.UserName = UserTable.UserIDWHERE EmailNotify.active =1AND UserTable.Date = DATE_SUB( CURDATE( ) , INTERVAL 1DAY )LIMIT 0 , 30[/code]What I need to find now is everyone who DID NOT do a backup the previous day and send an email based on that. FTPUsers has the users first and last names and other account info, UserTable includes the backup information including UserID, Date, RecordID among other information.I am looking for a join that will give me a list of people who want email notifications everyday about the backups, but did not actually do one the previous day so I can send an email saying "no backup perfromed on this date".....As I wrote that up their I figured out the answer. I do a similar join but instead of checking the date I use a NOT IN clause and give a list of the names returned from the first query, and it returns the records that were not included previously due to lack of backup activity. While looping through the first set of results I ad the UserID's to a list then can pass that into the second query. Maybe this will help someone else. and example of the query I'd pass would look like this.[code]SELECT EmailNotify.* , FTPUsers.Firstname, FTPUsers.LastName FROM EmailNotify LEFT JOIN FTPUsers ON EmailNotify.Username = FTPUsers.Username WHERE EmailNotify.active =1AND EmailNotify.UserName NOTIN ('David')LIMIT 0 , 30[/code]Does anyone else have another suggestion for a query that does not require the generated list?Thanks,Daiv Quote Link to comment https://forums.phpfreaks.com/topic/5456-not-included-in-join/ Share on other sites More sharing options...
fenway Posted March 23, 2006 Share Posted March 23, 2006 You could always use a LEFT JOIN ... (matching conditions) WHERE ... IS NULL, which will, by definition, return the non-matching rows. Quote Link to comment https://forums.phpfreaks.com/topic/5456-not-included-in-join/#findComment-19868 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.