468,242 Members | 1,546 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,242 developers. It's quick & easy.

Irregular Results From JOIN

233 100+
I have table A which has 202 unique record and table B which has 102 unique records. The 102 values in table B came from table A, so there are 100 other records in table A. However, the following query only returns 75 rows:

SELECT *
FROM TableA A JOIN
TableB B ON B.CONTACTID=A.CONTACTID

Given CONTACTID is the PK for each table, what am I doing wrong here?
Oct 10 '08 #1
4 1075
code green
1,726 Expert 1GB
if there are 102 matching IDs but only 75 are returned
it is probably the IDs have acquired extra spaces.
Use RTRIM. LTRIM
Oct 10 '08 #2
mcfly1204
233 100+
if there are 102 matching IDs but only 75 are returned
it is probably the IDs have acquired extra spaces.
Use RTRIM. LTRIM
I appreciate the response, but given the values in TableB came directly from TableA, there is not a chance of extra spaces being added.
Oct 10 '08 #3
ck9663
2,878 Expert 2GB
Is there a NULL value on your CONTACTID? I assume it's the primary key. Try doing a left join and see what the query returns.

-- CK
Oct 10 '08 #4
Delerna
1,134 Expert 1GB
Hi
I am assuming the fields are character fields because extra spaces are mentioned

given the values in TableB came directly from TableA, there is not a chance of extra spaces being added.
Umm, there is a chance
If the field in tableA is varchar and the field in tableB is char then there could be extra spaces added to the fields in tableB even though it's records came directly from tableA

Could this be the case?

Looking at your query I cannot see anything that you are doing wrong!
So it suggests a field type mismatch of some sort
Regards
Oct 11 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by dr | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.