mysql> WITH 2 extra rows(86321 and 28034) in profile_zipcodes,why is my third query NOT finding them?
SELECT zipcode from profile_zipcodes;
+---------+
| zipcode |
+---------+
| 01971 |
| 02110 |
| 02119 |
| 02124 |
| 02180 |
| 07086 |
| 07087 |
| 10008 |
| 10019 |
| 10021 |
| 10022 |
| 10024 |
| 10025 |
| 10095 |
| 10098 |
| 10099 |
| 10110 |
| 10112 |
| 10118 |
| 10131 |
| 10152 |
| 10157 |
| 10158 |
| 10159 |
| 10160 |
| 10161 |
| 10162 |
| 10166 |
| 10174 |
| 28034 |
| 33306 |
| 33319 |
| 50301 |
| 62334 |
| 63031 |
| 63131 |
| 63138 |
| 63141 |
| 63366 |
| 63376 |
| 67002 |
| 86321 |
+---------+
42 rows in set
mysql>
SELECT DISTINCT zip FROM profile_stats;
+-------+
| zip |
+-------+
| NULL |
| 01971 |
| 02110 |
| 02124 |
| 02180 |
| 07086 |
| 07087 |
| 10008 |
| 10019 |
| 10021 |
| 10022 |
| 10024 |
| 10025 |
| 10095 |
| 10098 |
| 10099 |
| 10110 |
| 10112 |
| 10118 |
| 10131 |
| 10152 |
| 10157 |
| 10158 |
| 10159 |
| 10160 |
| 10161 |
| 10162 |
| 10166 |
| 10174 |
| 33306 |
| 33319 |
| 50301 |
| 62334 |
| 63031 |
| 63131 |
| 63138 |
| 63141 |
| 63366 |
| 63376 |
| 67002 |
+-------+
40 rows in set (0.00 sec)
mysql>
SELECT * FROM profile_zipcodes WHERE profile_zipcodes.zipcode NOT IN
(SELECT DISTINCT zip FROM profile_stats);
Empty set (0.00 sec)
My php code actually runs this query:
DELETE FROM profile_zipcodes WHERE profile_zipcodes.zipcode NOT IN (SELECT DISTINCT zip FROM profile_stats)
Whenever a user changes their zip code or deletes their profile, and it was working fine, then suddenly I started noticing that zip codes with no profiles attached were remaining in the dynamically updated pull down box and debugging showed the query was still being run but the old zips were remaining and testing showed that an identically worded SELECT wasn't finding the orphan zips - it did work for a while, then it stopped?