473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Joins

Hello all:

I am trying to implement Automatic emailing sytem in our program. Basically, we want to send an email to our customers when specific event occurs. Events could be delay in delivery time by 30 mins, 60 mins and so. At the same time, I don't want to send 30 min delay email to a customer who was already notified so we register the event and the customer info in a table every time we send an email. I am using the following five tables for the emailing system.

Table A have AccountID and CustomerID. (Customer Info table)
values
--------
1,a
2,b

Table B have EventID, Event (Event info table)
values
--------
1,30
2,60

Table C have EmailID, Email (Email Info Table)
values
--------
1, aa@ads.com
2,bb@ads.com

Table D have AccountID,EmailID and EventID (Acct-Email-Event Link Table)
values
--------
1,1,1
1,1,2
1,2,1
1,2,2
2,1,1
2,1,2
2,2,1
2,2,2

Table E have CustomerID,EventID (Email Sent Info Table)
values
--------
a,1

I want to write a query that gives me the eventid and emailid of customers when a new event occurs. For instance, let us assume there are two customers A and B. Customer A's order gets delayed by 30 mins. The emailing sytem will send a 30 min delay email and will register the Event and the CustomerID in table E. Now, when Customer B's order gets delayed by 30 mins, I have to check table E to ensure that 30 min email is not already sent to that customer. In order to do this task, I wrote the following query, but it is not working for some reason.

Select A.CustomerID, C.Email,B.Event
from Table A
JOIN Table D on D.AccountID = A.AccountID
JOIN Table B on B.EVENTID = D.EVENTID
JOIN Table C on C.EmailID = D.EmailID
JOIN TABLE E on (E.CustomerID <> A.CustomerID and E.EVENTID <> B.EVENTID )

The results of the above query are
a,1,2
b,1,2

But, it needs to have the following in its result set.
b,1,1

Any help to solve the problem will be greatly appreciated.

Thanks
Jul 9 '07 #1
2 908
r035198x
13,262 8TB
Hello all:

I am trying to implement Automatic emailing sytem in our program. Basically, we want to send an email to our customers when specific event occurs. Events could be delay in delivery time by 30 mins, 60 mins and so. At the same time, I don't want to send 30 min delay email to a customer who was already notified so we register the event and the customer info in a table every time we send an email. I am using the following five tables for the emailing system.

Table A have AccountID and CustomerID. (Customer Info table)
values
--------
1,a
2,b

Table B have EventID, Event (Event info table)
values
--------
1,30
2,60

Table C have EmailID, Email (Email Info Table)
values
--------
1, aa@ads.com
2,bb@ads.com

Table D have AccountID,EmailID and EventID (Acct-Email-Event Link Table)
values
--------
1,1,1
1,1,2
1,2,1
1,2,2
2,1,1
2,1,2
2,2,1
2,2,2

Table E have CustomerID,EventID (Email Sent Info Table)
values
--------
a,1

I want to write a query that gives me the eventid and emailid of customers when a new event occurs. For instance, let us assume there are two customers A and B. Customer A's order gets delayed by 30 mins. The emailing sytem will send a 30 min delay email and will register the Event and the CustomerID in table E. Now, when Customer B's order gets delayed by 30 mins, I have to check table E to ensure that 30 min email is not already sent to that customer. In order to do this task, I wrote the following query, but it is not working for some reason.

Select A.CustomerID, C.Email,B.Event
from Table A
JOIN Table D on D.AccountID = A.AccountID
JOIN Table B on B.EVENTID = D.EVENTID
JOIN Table C on C.EmailID = D.EmailID
JOIN TABLE E on (E.CustomerID <> A.CustomerID and E.EVENTID <> B.EVENTID )

The results of the above query are
a,1,2
b,1,2

But, it needs to have the following in its result set.
b,1,1

Any help to solve the problem will be greatly appreciated.

Thanks
I don't see where all these joins come in.
not exists is tailor made for this.
However if these tables are not temporary, you may want to add a date field. i.e we may delay deliveries many times for the same customers.

Edit: I suppose you are using triggers for this.
Jul 10 '07 #2
I am working in an Interbase database. I am assuming MYSQL has JOINS similar to Interbase. Any how I figured out the solution myself.

Thanks
Jul 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: jgalzic | last post by:
Hi, I'm having trouble doing joins correctly on two tables. I've read up a lot about the different types of joins and tried lots of variations on inner, outer, and left joins with no avail....
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
4
by: Sri | last post by:
I am writing a download process in which i have a condition where i need to join four tables. Each table have lot of data say around 300000 recs. my question is when i am doing the joins on...
1
by: Prem | last post by:
Hi All Database Gurus, I am trying to write code which will produce all the possible valid queries, given tables and join information for tables. Right now i am just trying to construct all the...
4
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the...
4
by: michaelnewport | last post by:
Greetings, I like to write my inner joins as below, but someone at work tells me its not as 'performant' as using the 'inner join' statement. Is this true ? Is there a better way to write it...
7
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
2
by: narendra vuradi | last post by:
Hi I have a requirement where in i haev to convert the SQL from Oracle to the one which will run on the SQL server. in the Oracle Query i am doing multiple joins, between some 13 tables. and...
9
by: shapper | last post by:
Hello, I am used to SQL but I am starting to use LINQ. How can I create Left, Right and Inner joins in LINQ? How to distinguish the different joins? Here is a great SQL example:...
36
by: TC | last post by:
I've used Access for many years. Several times, I've encountered a bug which I refer to as the "Vanishing Joins" bug. When it happens, joins vanish randomly from queries. More specifically, all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.