DB2 join tables across schemas

I am trying to write a query that will join two schema tables, but for reasons I can't figure out will not return any rows.

SELECT * FROM NICK.COMP T1 INNER JOIN MIS.MAY2014 T2 ON T1.ID=T2.ID
FETCH FIRST 10 ROWS ONLY

Open in new window


SELECT * FROM NICK.COMP T1, MIS.MAY2014 T2 
WHERE T1.ID=T2.ID
FETCH FIRST 10 ROWS ONLY

Open in new window


Neither of these queries returns rows.  NICK AND MIS are schemas.  I get rows returned from both tables if I eliminate the join, just that the ID's do not match, so it has something to do with the join.  

Thanks for suggestions...
pansophyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenDBACommented:
Hi pansophy,

>> I get rows returned from both tables if I eliminate the join, just that the ID's do not match, so it has something to do with the join.  

That sounds like the issue.  If there are no matching IDs, no rows will be joined.

Joining tables from different schema is common.  With regards to that, your SQL looks good.


Kent
pansophyAuthor Commented:
I wish that was the issue.  I have verified that IDs match in the tables. The datatypes are not the same however, which I thought was the issue.  But I have tried to match tables from the two schemas that are identical and the join still fails.
Dave FordSoftware Developer / Database AdministratorCommented:
From a syntax perspective, your SQL looks correct. In order to help you better, let us know the data-type of the columns in question, and post some sample data.

-- DaveSlash
Kent OlsenDBACommented:
>> The datatypes are not the same however, which I thought was the issue.  

Bingo.  

If one data type is *int* and the other *float* or *double* a rounding error of less than a billion can cause a match failure.

If one data type is *int* and the other *varchar*, a match failure can occur depending upon which item is converted.  Convert '3' or '03' to integer and you get a 3.  Convert 3 to varchar and you get '3' which will match '3', but not an '03'.

You can specifically cast either column to be compatible with the other.  That should solve the join issue.  But it's a bad long-term solution as it reduces the effectiveness of the indexing.  If you have large tables performance could be a real issue.


Kent

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pansophyAuthor Commented:
I wasn't able to get 'cast' to solve the problem but I just changed the field type in the table and that solved it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.