25 February 2018

userCountries

My solution:
CREATE PROCEDURE userCountries() 
BEGIN 
  SELECT id, 
         country 
  FROM   users, 
         cities 
  WHERE  users.city = cities.city 
  UNION 
  SELECT DISTINCT id, 
                  "unknown" AS country 
  FROM   users, 
         cities 
  WHERE  users.city NOT IN (SELECT city 
                            FROM   cities) 
  ORDER  BY id; 
END