S12000
S12000

Reputation: 3396

SQL filter all values in one column but not in another one

I have created a query which is as follows:

SELECT t1.blah , t2.blah
FROM table1 AS t1
    INNER JOIN table2 AS t2 ON (t1.id = t2.id)

So the results looks like

t1.blah   t2.blah
=================
390       400
401       401
501       501
36        36

What I look for is to extract all values that are in t1.blah but never in t2.blah. In my example I should get as final result the value 390.

I tried to do some test with HAVING but I did not succeed. How can I achieve that in mysql for instance.

Upvotes: 1

Views: 356

Answers (1)

Madhur Bhaiya
Madhur Bhaiya

Reputation: 28834

You can put one more condition on blah not matching in both the tables:

SELECT t1.blah , t2.blah
FROM table1 AS t1
    INNER JOIN table2 AS t2 
            ON t1.id = t2.id
               AND t1.blah <> t2.blah

Upvotes: 2

Related Questions