My table coordinates
is:
id (PK) SERIAL, address (VARCHAR), city (VARCHAR), latitude (VARCHAR), longitude (VARCHAR)
I have a list of 10,000 addresses which I'm looping through to retrieve the corresponding latitude/longitude if the address exists in the table.
The SELECT
query looks like:
SELECT ADDRESS, CITY, LATITUDE, LONGITUDE FROM coordinates WHERE address = ? AND city = ?
I then check the result set to see if there was a match. The other 9,999 addresses are then looped through the query above which takes far too long.
Is there a way to create ONE query that contains all 10,000 addresses and returns a result set with 4 columns: |address|city|latitude|longitude|
Any address not found should have an empty (0 or null) lat/lon value in that result set column. I'm assuming I could then loop the result set to identify anything missed, much faster than 10,000 statements.
What's the best approach?