Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to query if either EMPLOYEE.EMAIL1 or EMPLOYEE.EMAIL2 do not have a matching entry?
    primarykey
    data
    text
    <p>In continuation to a question posted by me on <a href="https://stackoverflow.com/q/4612710/181870">Can my use case explained be solved in a single query without affecting performance?</a>, I've a different requirement now and I wonder whether this could be again solved in a single query without affecting performance. My new requirement explained below:</p> <p>There are 2 tables involved:</p> <pre><code>Table 1: EMPLOYEE (column1, column2, email1, email2, column5, column6) Table 2: EMAILLIST (email) </code></pre> <p>My new requirement is, if <em>both</em> EMPLOYEE.EMAIL1 and EMPLOYEE.EMAIL2 have a matching entry in EMAILLIST table, then this row should be ignored. Hence, if either EMPLOYEE.EMAIL1 or EMPLOYEE.EMAIL2 do not have a matching entry (which means atleast one of the column will have a matching entry), I expect this row should be returned. Because either one of the email do not have a matching entry, I need a identification in SELECT clause itself on which email (email1 or email2) did not have a matching entry in EMAILLIST table.</p> <p><strong>Example:</strong> </p> <pre><code>INSERT INTO EMAILLIST (email) VALUES ('test1@domain.com'); INSERT INTO EMPLOYEE (column1, column2, email1, email2, column5, column6) VALUES ('c1', 'c2', 'test1@domain.com', 'test2@domain.com', 'c5', 'c6'); </code></pre> <p>I expect to return with some identification in query output on which one of the email do not have a matching entry like this:</p> <pre><code>EMAIL1 | EMAIL2 | EMAIL1MATCHED | EMAIL2MATCHED test1@domain.com | test2@domain.com | Yes | No </code></pre> <p>We're using PostgreSQL v8.2.3, if it matters.</p> <p><strong>UPDATE:</strong> My table size are little huge: EMPLOYEE has got 165018 records and EMAILLIST has got 1810228 records</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload