By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

Irregular Results From JOIN

100+
P: 233
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
Share this Question
Share on Google+
4 Replies


code green
Expert 100+
P: 1,726
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

100+
P: 233
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
Expert 2.5K+
P: 2,878
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
Expert 100+
P: 1,134
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.