Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7701343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:57:40+00:00 2026-05-31T22:57:40+00:00

I have an query that has been giving me trouble. I think there is

  • 0

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 '%@%'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:57:41+00:00Added an answer on May 31, 2026 at 10:57 pm

    A couple of options. The most efficient is to use an analytic function.

    SELECT *
      FROM (
        SELECT table1.indident_id, 
               table1.incident_detail_id, 
               table1.incdent_entered_date, 
               table1.entering_employee, 
               table2.EMAIL,
               row_number() over (partition by table2.cust_id
                                      order by table2.updated_date desc) rnk
          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 '%@%'
      )
     WHERE rnk = 1
    

    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_id subquery

        SELECT 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.update_date = (SELECT MAX(t2_inner.update_date)
                                       FROM table2 t2_inner
                                      WHERE t2_inner.cust_id = table1.cust_id)
           AND table2.EMAIL NOT IN ('NONE','none','none@none.com')
           AND table2.EMAIL like '%@%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a linq union statement that has been giving me some trouble and
On Sql Server 2008, I have a slow-running update query that has been working
We have a query in our system that has been a problem in the
This seems rather simple but it has been giving me a headache. I have
I have the following query with many LEFT JOIN clauses that has 7 result
Suppose I have a SQL Query that isn't really nice. The SQL Query has
I have objects that has a DateTime property, how can i query for the
I have a query that exhausts the default MAXRECURSION limit of 100. Giving me
Hi I have some problems that has been bothering me for a week. I
Edit: using SQL Server 2005. I have a query that has to check whether

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.