SQL help please!
Discussion
I'm trying to work out the correct SQL to query a two fields in each of four tables in a database and combine all the results into a single result, but as it's two days before xmas my brain just ain't up to it
Each of the four tables contains a field for an e-mail address and a true/false field to indicate whether they've signed up for a newsletter.
The table.field designations are:
tblcompanies.CompanyContactEmail
tblcompanies.CompanyNewsletterOptOut
tbldelegates.DelegateEmail
tbldelegates.DelegateNewsletterOptOut
tblhosts.HostEmail
tblhosts.Host.NewsletterOptOut
tbltrainers.TrainerEmail
tbltrainers.TrainerNewsletterOptOut
Is there any way of querying the above to dump all the email address into a single 'email' result when each of the ***NewsletterOptOut values are -1.


Each of the four tables contains a field for an e-mail address and a true/false field to indicate whether they've signed up for a newsletter.
The table.field designations are:
tblcompanies.CompanyContactEmail
tblcompanies.CompanyNewsletterOptOut
tbldelegates.DelegateEmail
tbldelegates.DelegateNewsletterOptOut
tblhosts.HostEmail
tblhosts.Host.NewsletterOptOut
tbltrainers.TrainerEmail
tbltrainers.TrainerNewsletterOptOut
Is there any way of querying the above to dump all the email address into a single 'email' result when each of the ***NewsletterOptOut values are -1.

judas said:
I'm trying to work out the correct SQL to query a two fields in each of four tables in a database and combine all the results into a single result, but as it's two days before xmas my brain just ain't up to it ![]()
Each of the four tables contains a field for an e-mail address and a true/false field to indicate whether they've signed up for a newsletter.
The table.field designations are:
tblcompanies.CompanyContactEmail
tblcompanies.CompanyNewsletterOptOut
tbldelegates.DelegateEmail
tbldelegates.DelegateNewsletterOptOut
tblhosts.HostEmail
tblhosts.Host.NewsletterOptOut
tbltrainers.TrainerEmail
tbltrainers.TrainerNewsletterOptOut
Is there any way of querying the above to dump all the email address into a single 'email' result when each of the ***NewsletterOptOut values are -1.
Yep
Just need to union the select statements together
Select CompanyContactEmail
from tblcompanies
where
CompanyNewsletterOptOut = -1
Union Select DelegateEmail
from tbldelegates
where
DelegateNewsletterOptOut= -1
Union Select HostEmail
from tblhosts
where
HostNewsletterOptOut = -1
Union Select TrainerEmail
from tbltrainers
where
TrainerNewsletterOptOut = -1;
That's what I keep wondering too. 'Spec' is an internal working term, which refers to the various impossible, contradictory and ever changing requirements as dreamt up by the client on whatever planet they happen to be at the time and then 'translated' via the boss into something like 'whatever keeps the client happy (ie, paying the bills)'.


Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff