Jump to content

not included in join


daiv

Recommended Posts

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 EmailNotify
LEFT JOIN FTPUsers ON EmailNotify.Username = FTPUsers.Username
LEFT JOIN UserTable ON EmailNotify.UserName = UserTable.UserID
WHERE EmailNotify.active =1
AND UserTable.Date = DATE_SUB( CURDATE( ) , INTERVAL 1
DAY )
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 =1
AND EmailNotify.UserName NOT
IN (
'David'
)
LIMIT 0 , 30[/code]


Does anyone else have another suggestion for a query that does not require the generated list?


Thanks,
Daiv
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.