Query duplicates and blank (1 Viewer)

hllary

Registered User.
Local time
Yesterday, 23:14
Joined
Sep 23, 2019
Messages
80
I think I should know this...

I'm trying to find duplicates records on two table and blanks. I've linked two tables and it shows all the records that are in both tables. But I can't get it to include all the records that are empty in the ecp effectivity column.

Code:
SELECT REV1Val_WP_Tracking.*
FROM REV1Val_WP_Tracking INNER JOIN TM_tbl ON REV1Val_WP_Tracking.[ECP Effectivity] = TM_tbl.TrackingID
WHERE (((REV1Val_WP_Tracking.[ECP Effectivity])=[TM_tbl].[TrackingID]) OR REV1Val_WP_Tracking.[ECP Effectivity] =null);
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:14
Joined
May 7, 2009
Messages
19,230
use Left Join, maybe it will help.
 

hllary

Registered User.
Local time
Yesterday, 23:14
Joined
Sep 23, 2019
Messages
80
Something weird is happening. Instead of having a line between linked items, it's only showing a dot beside each item.

Thanks for your help. I'll do a work around, make two queries and go from there.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:14
Joined
Oct 29, 2018
Messages
21,467
Something weird is happening. Instead of having a line between linked items, it's only showing a dot beside each item.

Thanks for your help. I'll do a work around, make two queries and go from there.
If you need more help, consider posting a sample db. Good luck!
 

plog

Banishment Pending
Local time
Today, 01:14
Joined
May 11, 2011
Messages
11,643
I can't get it to include all the records that are empty in the ecp effectivity column

Code:
FROM REV1Val_WP_Tracking INNER JOIN TM_tbl ON REV1Val_WP_Tracking.[ECP Effectivity] = TM_tbl.TrackingID

Your words and code can never line up. Regardless of your WHERE clause, that INNER JOIN clause will never allow null [ECP Effectivity] records through. You cannot JOIN on null values, so if [ECP Effectivity] is null, it will never pull records back from that table.

I suggest you post sample data to demonstrate your issue. Please provide 2 sets:

A. Starting data from your tables. Include table and field names and enough data to cover all cases.

B. Expected results of A. Show what data you expect your query to return when you feed it the data from A.

Again, 2 sets of data--starting and ending.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:14
Joined
Feb 19, 2002
Messages
43,257
You have a syntax/logic error in your query.
1. You cannot use "= Null" to test for null. No conditional statement where one object is null will EVER return true EXCEPT for the IsNull() function or the SQL predicate "Is Null".

See the changes below. I removed the extraneous parentheses since they just confuse the statement without adding any meaning.

SELECT REV1Val_WP_Tracking.*
FROM REV1Val_WP_Tracking INNER JOIN TM_tbl ON REV1Val_WP_Tracking.[ECP Effectivity] = TM_tbl.TrackingID
WHERE REV1Val_WP_Tracking.[ECP Effectivity] = [TM_tbl].[TrackingID] OR REV1Val_WP_Tracking.[ECP Effectivity] Is Null;

Now, this may still not be logically correct but at least it is syntactically correct.
 

Users who are viewing this thread

Top Bottom