I've got a database table of zip codes and am grouping zip codes into regions. So I have two tables, one with all of the zip code information and one with the region id and assigned zip code.
I'd like the system to do the following with only one trip to the database. I need the results to display the entire list of zip codes not yet assigned to a region, sorted by county.
So the results will look like this -
12344 - 12345 - 12345 - 12347
22344 - 22345 - 22345 - 22347
Select Distinct County, zipcode from the zip code table where the zip code is not in the regions table.
I'd then like to store these results in an array that I can go through to output the results.
Currently I'm pulling the distinct county, outputting in a foreach loop, and then running a new query to pull the zipcode and for each county.
Is it possible to do this with only one trip to the database? I'm running MySQL and PHP.