Wrox Home  
Search P2P Archive for: Go

  Return to Index  

proasp_howto thread: Problem With Left Join


Message #1 by "David Yee" <david@r...> on Fri, 22 Feb 2002 14:44:50 +0800
Hello,

I've got good news and bad news for you.  The bad news is that your 
query, as stated, doesn't make sense.  Think about it: you want your 
results to contain rows where TblMemAccess.MemID = 44 and you also want 
your results to contain row where TblMemAccess.MemID <> 44 (or Null).  
Clearly, MemID can't be equal to 44 and not equal to 44 at the same 
time.  This is why your results are not satisfactory.

What it *looks* like you want to do is use a UNION statement to bring 
these two disparate results together as one.  The MS Access query builder 
does not directly support UNION, but access does.  You'll have to enter 
the SQL statement by manually.  Try something like:

select tblpurchasecat.catid, tblpurchasecat.catname, tblmemaccess.memid
from tblpurchasecat a, tblmemaccess b
where a.catid = b.catid
and b.memid = 44
UNION
select tblpurchasecat.catid, tblpurchasecat.catname, tblmemaccess.memid
from tblpurchasecat a, tblmemaccess b
where a.catid = b.catid
and b.memid is null

I didn't take the time to test this out, but it's the right approach.  
debugging is easy, just get each half of the union to return the rows you 
want before union-ing them.  If you are not familiar with UNION, keep in 
mind that the number of columns in the two select statement must be the 
same, and cooresponding columns must have the same domain (e.g., dates 
must line up with dates, number with numbers, boolean with boolean, etc).

Good luck,

Brad Duhaime
bduhaime@s...


  Return to Index