I want to return all the postcodes in table1 that are active and that dont have any items in table2 that share the same coordinates (lat,lng).
I.e. in the below return :
AB11AC
I know there are several method where you are just checking one column, but not sure how to adapt for 2 columns. Should I just concatenate the 2 columns together in the query or is there a more efficient method? My tables each have around 2 million entries.
table1:
postcode lat lng active
-------------------------
AB11AA 55 1 Y
AB11AB 56 1 Y
AB11AC 57 1 Y
table2:
postcode lat lng active
--------------------------
AB11AA 55 1 Y
AB11AD 56 1 Y
AB11AE 59 1 Y
You can use a
LEFT JOIN:See SQL Fiddle with Demo
Or you can use a
NOT EXISTSin theWHEREclause:See SQL Fiddle with Demo