In the code below I get an error from the WHERE clause in the subquery. It sais "column ambiguously defined". I don't understand how any column can be ambiguously defined because everytime I specify from which table the column originates.
WITH everything AS
(
SELECT *
FROM hvc_hvvisitresult a, hvc_am0 b, hvc_visitresultdetails c, hvc_ar0 d
WHERE a.am0_nrid = b.am0_nrid
AND a.hvvisitresult_nrid = c.hvvisitresult_nrid
AND c.ar0_nrid = d.ar0_nrid
AND hvoutcome_nrid = 2
AND TO_CHAR(dateonly, 'yyyy') = 2008
AND TO_CHAR(dateonly, 'mm') = 1
)
SELECT DISTINCT description
FROM everything a
WHERE EXISTS (SELECT *
FROM everything b
WHERE a.ar0_nrid <> b.ar0_nrid
AND a.am0_nrid = b.am0_nrid
AND a.so0_nrid = b.so0_nrid
AND a.dateonly = b.dateonly)
Could someone help me please?