Irregular Results From JOIN

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcfly1204
    New Member
    • Jul 2007
    • 233

    Irregular Results From JOIN

    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.C ONTACTID

    Given CONTACTID is the PK for each table, what am I doing wrong here?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    if there are 102 matching IDs but only 75 are returned
    it is probably the IDs have acquired extra spaces.
    Use RTRIM. LTRIM

    Comment

    • mcfly1204
      New Member
      • Jul 2007
      • 233

      #3
      Originally posted by code green
      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.

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        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

        Comment

        • Delerna
          Recognized Expert Top Contributor
          • Jan 2008
          • 1134

          #5
          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

          Comment

          Working...