I'm getting the error in the following query:
SELECT DISTINCT UNIQUE_ID as uid, CONFIDENCE_IS_SAME FROM
(
(SELECT UNIQUE_ID, CONFIDENCE_IS_SAME, FIRST_NAME, LAST_NAME, POSTAL_CODE
FROM DANIEL.UNIQUE_PHYSICIAN WHERE
DANIEL.UNIQUE_PHYSICIAN.FIRST_NAME = ''
AND
DANIEL.UNIQUE_PHYSICIAN.LAST_NAME = ''
AND
DANIEL.UNIQUE_PHYSICIAN.IS_ROOT_PHYS = 0
AND
DANIEL.UNIQUE_PHYSICIAN.POSTAL_CODE = '')
INNER JOIN
(SELECT
MAX(CONFIDENCE_IS_SAME) OVER (PARTITION BY ROOT_ID) max_conf
FROM DANIEL.UNIQUE_PHYSICIAN
WHERE DANIEL.UNIQUE_PHYSICIAN.FIRST_NAME = '' AND
DANIEL.UNIQUE_PHYSICIAN.LAST_NAME = '' AND DANIEL.UNIQUE_PHYSICIAN.IS_ROOT_PHYS = 0
AND DANIEL.UNIQUE_PHYSICIAN.POSTAL_CODE = '')
ON CONFIDENCE_IS_SAME = max_conf);
Best Answer
You need an alias for both derived tables. And the outer pair around the
from
clause is useless.But the join isn't needed in the first place. Your query can be simplified to:
You don't need to select
first_name
,last_name
andpostal_code
in the inner select as you don't use them in the outer select. This can make the query potentially more efficient.Additionally, the condition
unq.last_name = ''
won't do what you think it does. Oracle does not have an "empty string". A string with length zero (''
) will be stored asNULL
, so what you really want is probably: