Objective:
The intent of this query is to select all of the distinct values in one column that don't exist in a similar column in a different table.
Current Query:
SELECT DISTINCT Table1.Column1
FROM Table2, Table1
WHERE Table1.Column1 <> Table2.Column1
Results From Query:
What happens when I try to run this query is the progress bar fills up almost immediately but then it pretty much freezes and doesn't do anything else as far as I can see. When I use an = sign instead of <> it outputs the values that are equal just fine and if I replace Table2.Column1 with an actual actual value it works just fine.
I just ran it again while typing this question and the above query gave me an answer this time but it has all of the DISTINCT values for the column not all of the values unique to just that table like it should.
Any ideas on what I'm doing wrong or missing here?
Like this
SELECT DISTINCT Table1.Column1
FROM Table1
WHERE NOT EXISTS( SELECT * FROM Table2
WHERE Table1.Column1 = Table2.Column1 )
You want NOT EXISTS, not "Not Equal"
By the way, you rarely want to write a FROM clause like this:
FROM Table1, Table2
as this means "FROM all combinations of every row in Table1 with every row in Table2..." Usually that's a lot more result rows than you ever want to see. And in the rare case that you really do want to do that, the more accepted syntax is:
FROM Table1 CROSS JOIN Table2