I have an query that has been giving me trouble. I think there is probably an easy solution, but please help me where you can!
My main problem is that there are often multiple emails per cust_id. There are unique identifiers such as a sequence number (seq_no) and updated date (updated_date). I only want the newest email address to show for any one customer.
By the way, this is an oracle DB.
Any suggestions?
SELECT DISTINCT
table1.indident_id,
table1.incident_detail_id,
table1.incdent_entered_date,
table1.entering_employee,
table2.EMAIL
FROM table1
left outer join table2 on table1.cust_id=table2.cust_id
WHERE table1.incdent_entered_date>=current_date-4
AND table1.table1.incident_detail_id=(select min(table1.table1.incident_detail_id)from table1)
AND table2.EMAIL NOT IN ('NONE','none','none@none.com')
AND table2.EMAIL like '%@%'
A couple of options. The most efficient is to use an analytic function.
Less efficiently, but something that will work in just about any database, would be to do something similar to what you’re currently doing with the
incident_detail_idsubquery