This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have 2 tables TABLE A ID PRICE DATE_OF_DATE countrycode
TABLE B countrycode exchange_rate
I used the code: CREATE TABLE ALL as select a.ID, a.price, b.exchange_rate, a.a.DATE_OF_DATA from TABLEA a, TABLEB b where a.DATE_OF_DATA = b.DATE_OF_DATA and a.countrycode = b.countrycode order by a.barra_id, a.DATE_OF_DATA; RUN;
It's giving me 2 entried for every ID and DATE i.e.
ID price exchange Date A 1 2.34 2001-01-01 A 1 2.34 2001-01-01 B 1.1 2.35 2001-01-02 B 1.1 2.35 2001-01-02
I only want: ID price exchange Date A 1 2.34 2001-01-01 B 1.1 2.35 2001-01-02
first of all you didn't mention these, DATE_OF_DATA, barra_id , column in your table B and A description respectively and you are using it in the query. second thing you should fulfill the equi join condition. equi join should be between primary, foreign relationship.
i think this is not the case of distinct. try equi join correctly.
If you're just playing in development (e.g. setting up test data as a one-off) then SELECT DISTINCT will work fine but it's the first reaction of the SQL beginner when a joined query is producing duplicate rows.
As Adeel says, you need to get the join condition right, and that means ensuring that each primary key column in table A is joined to a corresponding foreign key column in table B. It currently looks like you're missing one, but it's not clear which from your example.
Also when posting code please try to copy and paste from the actual code you're testing (if edited a little for brevity). It's not easy to help you when it's clear that your code as given couldn't possibly produce the output you say it does. Also please use the UBB CODE tags (next to the Graemlins) when posting code.