The query below works great. It pulls ZIP codes from a table “submission,” groups them, then lists them in order.
I have another table called “addresses” that has ZIP codes as well, which may or may not be duplicates of the ZIP codes in “submission.”
How could I join any ZIP codes appearing in “addresses” (the second table), but not appearing in the first table, and add them to the list created by the query below?
$query2 = "SELECT submissionid, zip
FROM submission
GROUP BY zip
ORDER BY zip ASC";
you need the union word and you can’t use the submissionid
union will give you distinct values by default. If you need the id, you can do something like this over the resulting query to select a specific one:
MySQL: Avoid selecting columns with the same userid
This one uses the lowest id of a set of identical zips.