I'm trying to join two tables together that would return a classification of a region based on the city and postcode.
TABLE A contains information about the customer and their location
TABLE B contains information about suburbs, postcodes and regional classifications
I would like to match the two tables in order of preference:
- Suburb and Postcode
- Postcode
- Suburb
I'm having a difficult time joining the two tables. I have this code and so far, it only matches the first preference. The classification returns a NULL if the postcode OR suburb is NULL.
SELECT
A.*, B.Classification
INTO NEWTABLE
FROM TABLEA AS A
LEFT JOIN TABLEB AS B
ON A.City = B.City
AND A.Postcode = B.Postcode
I feel the solution is quite simple but I just can't get my head around the SQL language. I'm using Microsoft SQL. Thank you so much!