[thelist] SQL Assistance

rudy r937 at interlog.com
Tue Apr 1 11:33:57 CST 2003


switch the order of your joins around so that you get the contact and module
together

SELECT Contacts.ContactID
     , Module.ModuleContactID
     , Module.ModuleID
     , Module.Module
  FROM Contacts
INNER
  JOIN [Module]
    ON Contacts.ContactID = Module.ModuleContactID
 WHERE Module.Module in ('CO','COWEB')

if you can save that as a query (i.e. an access "view"), so much the better,
it'll make the next query easier to write (and read)

> (There is another column available that will allow me to sort
> and determine which address I want .. I left that column out for now)

well, that's the key to your problem, so you should have left it in   ;o)

SELECT Contacts.ContactID
     , Module.ModuleContactID
     , Module.ModuleID
     , Module.Module
     , OMG.AddressType
  FROM savedquery
LEFT OUTER
  JOIN Address OMG
    ON ContactID = OMG.AddressContactID
 where OMG.somecolumn
     = ( select somecolumn
           from Address
          where AddressContactID = OMG.AddressContactID
            and somecondition )

note the use of the OMG correlation variable to distinguish the rows of the
outer query from the rows of the correlated subquery

rudy



More information about the thelist mailing list