So when you query with = you will get all rows I've highlighted in red above, which is what you expected (even though it's not the correct way to achieve it, the correct way would be to use an INNER JOIN). No when you change = to <> you will get all the rows for which the agency_code is 3 and the first column of the table above isn't equal to the last column, which is pretty much most of the rows that have agency_code = 3.