Solved

Query returning records it shuold not be returning

Posted on 2013-11-16
4
253 Views
Last Modified: 2013-11-16
I have a query with a table as its record source.  The are two fields in the query that I am setting a criteria for.  The are "Email" (text field), and "AssociationID" (numeric).

I don't want the query to return the records that have no number in "AssociationID" and have no text in "Email".  

But the query IS only returning the record that have a number in the "AssociationID" field but IS ALSO returning the records if the "Email" field is blank and it should not be.

Here is the SQL of the query:

SELECT tblAssociations.AssocName, [LastName] & ", " & [FirstName] AS Name, tblIndividuals.Email, tblIndividuals.AssociationID, tblIndividuals.FirstName, tblIndividuals.LastName
FROM tblIndividuals RIGHT JOIN tblAssociations ON tblIndividuals.AssociationID = tblAssociations.AssociationID
WHERE (((tblIndividuals.Email) Is Not Null) AND ((tblIndividuals.AssociationID) Is Not Null))
ORDER BY tblAssociations.AssocName, [LastName] & ", " & [FirstName];
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 250 total points
ID: 39653372
try this.
SELECT tblAssociations.AssocName, [LastName] & ", " & [FirstName] AS Name, 
       tblIndividuals.Email, 
	   tblIndividuals.AssociationID, 
	   tblIndividuals.FirstName, 
	   tblIndividuals.LastName
  FROM tblIndividuals 
 RIGHT JOIN tblAssociations 
    ON tblIndividuals.AssociationID = tblAssociations.AssociationID
 WHERE (((tblIndividuals.Email) Is Not Null)
   AND trim(tblIndividuals.Email) <> '' 
   AND ((tblIndividuals.AssociationID) Is Not Null))
 ORDER BY tblAssociations.AssocName, [LastName] & ", " & [FirstName];

Open in new window

0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 250 total points
ID: 39653396
Or this:

SELECT a.AssocName, [LastName] & ", " & [FirstName] AS Name, i.Email, i.AssociationID, i.FirstName, i.LastName
FROM tblAssociations a LEFT JOIN tblIndividuals i ON a.AssociationID = i.AssociationID
WHERE NZ(i.Email,"") <> ""  AND  NZ(i.AssociationID ,"") <> "" 
ORDER BY a.AssocName, [LastName] & ", " & [FirstName];

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 39653400
Also, if you're not allowing NULLs in associationID (ie: un-matched records), you can use an INNER JOIN without the associationID criteria:

SELECT a.AssocName, [LastName] & ", " & [FirstName] AS Name, i.Email, i.AssociationID, i.FirstName, i.LastName
FROM tblAssociations a INNER JOIN tblIndividuals i ON a.AssociationID = i.AssociationID
WHERE NZ(i.Email,"") <> "" 
ORDER BY a.AssocName, [LastName] & ", " & [FirstName];

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 39653442
Steve,

These all should give you the results you're looking for, but I'd recommend actually using the INNER JOIN in my last post (http:#a39653400).  That right join from what I can tell is overkill, and might (possibly) be problematic if you are using this as a recordsource for a form whose data you want to update.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question