I have table A Stores which have store information. Table B have all states information. I need to join table A to B to get all the states where store is open. Now I need to find all the states where store is in not open.
Table A:
Stores | StateCode |
---|---|
Store A | MP |
Store B | UP |
Store B | MP |
Store C | JK |
Table B:
StateCode | StateName |
---|---|
MP | Madhya Pradesh |
UP | Uttar Pradesh |
JK | Jammu Kashmir |
Output table:
Stores | StateCode | StateName |
---|---|---|
Store A | UP | Uttar Pradesh |
Store A | JK | Jammu Kashmir |
Store B | JK | Jammu Kashmir |
Store C | UP | Uttar Pradesh |
Store C | MP | Madhya Pradesh |
I have tried this:
SELECT *
FROM tableB
LEFT OUTER JOIN tableA
ON tableA.<stateCode> = tableB.<stateCode>
WHERE tableA.<stateCode> IS NULL