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 3661568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:19:11+00:00 2026-05-19T01:19:11+00:00

Am mainly looking at improving the performance of the query and also whether be

  • 0

Am mainly looking at improving the performance of the query and also whether be able to solve in a single query for one of my use case explained below:

There are 2 tables involved:

Table 1: EMPLOYEE (column1, column2, email1, email2, column5, column6)
Table 2: EMAILLIST (email)

My requirement is, I want to get/fetch all records from the table EMPLOYEE with the condition that either email1 or email2 do not have a matching entry in EMAILLIST table. To put it simply, if either email1 or email2 matches in EMAILLIST table, then those records should be ignored.

In this case, EMPLOYEE.EMAIL1, EMPLOYEE.EMAIL2 and EMAILLIST.EMAIL will always have single email address stored.

We’re using PostgreSQL v8.2.3, if it matters.

Any pointers/ideas/logic are appreciated.

UPDATE: Currently, we’ve implemented in this way: Fetched all records from EMPLOYEE table and stored in a Java object and for each entry (for loop), this in turn checks in EMAILLIST table, which is costly in terms of performance.

  • 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-19T01:19:12+00:00Added an answer on May 19, 2026 at 1:19 am

    The most efficient way to handle this for every rdbms I’ve dealt with is to handle it with outer joins:

    SELECT whatever
    FROM employee AS e
    LEFT JOIN emaillist AS em1 ON e.email1 = em1.email
    LEFT JOIN emaillist AS em2 ON e.email2 = em2.email
    WHERE em1.id IS NULL
        AND em2.id IS NULL
    

    In general, I think you’ll find that any case where you put database queries into a loop will be, ummm, suboptimal. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thank you for the answers. :) I'm mainly looking to host my website with
We're looking at removing all of the static resources (mainly images) in our ASP.NET
I am tasked with improving the performance of a particular page of the website
I'm looking to create emails, mainly HTML, based on templates - I'd really like
I'm looking for a build automation solution for use with a Visual Studio solution
Mainly looking for PHP minifier. Online copy > paste > output, would be a
What are various tools to convert Python scripts to C. I am mainly looking
I am looking into designing completely custom UI component mainly for Windows Phone 7
I'm looking into css frameworks, mainly for resets, structuring my projects better, etc. I
I am looking for a JavaScript library that manipulates arrays of objects, mainly for

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.