-1

I've got a query to select distinct results with two tables which returns email addresses that don't occur in table2, but I'm having trouble also selecting data from the Table 2.First in this query for all rows with distinct emails. Is it possible to combine select statements in SQLite/DBbrowser in this way? My current query with the syntax I've tried is below

TABLE1:

table1email Firstlast
[email protected] Jim Robinson
[email protected] Clark Stevenson

TABLE2:

table2email First Last
[email protected] Jim Robinson
[email protected] Susan Peters
[email protected] Clark Stevenson

QUERY:

SELECT table1email
FROM TABLE1
EXCEPT
SELECT DISTINCT table2email
SELECT First
FROM table2

1 Answer 1

1

The question doesn't seems to be very clear. Whatever I can understand from the question this seems to be the solution you are looking for.

SELECT table1email FROM table1 
WHERE table1email NOT IN (
    SELECT table2email FROM table2
);

This will work even if table2 have duplicate entries. But this will result duplicate entries from table1. If that is also needs to be eliminated, DISTINCT keyword can be used.

SELECT DISTINCT table1email FROM table1 
WHERE table1email NOT IN (
    SELECT table2email FROM table2
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.