I am working on a query that will assign users to a specific building based on their lat/long coordinates. The query does work and assigns a building id value to the associated user but I would like to assign a value of "unknown location" if no building exists at the users current location.
Essentially, IF location known SET u.building_id = b.building_id, ELSE SET u.building_id = 'unknown location';
The current query is as follows:
UPDATE USERS u
JOIN BUILDINGS b ON u.latitude BETWEEN (b.latitude - 0.001) AND (b.latitude + 0.001)
AND u.longitude BETWEEN (b.longitude - 0.001) AND (b.longitude + 0.001)
SET u.building_id = b.building_id
I am thinking this could be accomplished by adding an SQL cases? How should I approach this?