Skip to content
Advertisement

SQL – Select using attributes from two tables

I am having an issue in extracting data using data of two tables in SQL.

This returns A, B, C, D where E in T2 is not ZZZ. However, when I add another where clause like below, it returns data where T2 is ZZZ also.

This ignores “T2.E <> ‘ZZZ'” part, but “D<>0” is not ignored. Why is this happening?

Advertisement

Answer

Because you have duplicates in Table_two. For some of those duplicates, one has the value of ZZZ and the other does not.

You are using the wrong logic if you want to exclude rows that have a ZZZ in table_two. I would recommend NOT EXISTS:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement