|
Posted by cluthz on 05/14/07 22:51
Hi there,
I have a table of accounts and emailaddresses, as an account can have more
then one email address.
The email address table has an indicator (email_primaryemail) as to which
email address for a particular account is the primary email address (yes /
no field).
If I want to get to perform a search ONLY on accounts that have no email
address in a single SQL statement (that will also have other search criteria
in it constructed from PHP code depending upon what user entered on a search
web form) would the following method work:
Select * from accounts
left join emailaddresses on (account_key = email_foriegnkey)
where (my other dynamically built search criteria on account) AND
email_primaryemail IS NULL
group by account_key
My doubt comes from the fact when you perform a left join like about and
then have a "group by", for the other fields not grouped on, how do you know
from which of the available results available Mysql compares on.
It's quite a hard question to ask actually and hopefully I have made it
clear. Reading that last paragraph back, probably not, but hopefully someone
will know what I'm getting at.
Thanks in advance if anyone can guide me.
[Back to original message]
|