I started out with a query as such:
SELECT A.*
FROM TABLE_A A
INNER JOIN TABLE_B B
ON A.YEAR = B.YEAR
WHERE A.ID IN (SELECT ID FROM TABLE_B)
The above query gave me duplicate records, so I added the DISTINCT
keyword as such:
SELECT DISTINCT A.*
FROM TABLE_A A
INNER JOIN TABLE_B B
ON A.YEAR = B.YEAR
WHERE A.ID IN (SELECT ID FROM TABLE_B)
This second query gave me the following error:
ORA-00932: inconsistent datatypes: expected - got CLOB
- 00000 - "inconsistent datatypes: expected %s got %s"
I finally corrected the query and eliminated the duplicate records by moving the condition in the WHERE
clause to the INNER JOIN
like this:
SELECT A.*
FROM TABLE_A A
INNER JOIN TABLE_B B
ON A.YEAR = B.YEAR
AND A.ID = B.ID
I just don't understand why the second query did not work. Why does adding the DISTINCT
keyword here suddenly cause an issue?