 
 JOIN location AS multipoint_location
 ON multipoint_location.locationid = txconfig.locationid
-
-JOIN geographicreference AS point_georef
-ON point_georef.locationid = point_location.locationid
-
--- select only WGS84 datum LatLngs
-WHERE point_georef.georeferencetypeid = 3
-
 -- select points where one is a "POINT", and the other isn't
 AND point_location.locationtypeid = 4 
 AND multipoint_location.locationtypeid != 4

UNION ALL

-- query 2: select point transmitters
SELECT
point_location.locationid,
point_georef.northing,
point_georef.easting,
multipoint_location.locationid 


FROM location as point_location



JOIN location AS multipoint_location
ON multipoint_location.locationid = rxconfig.locationid
-- select points where one is a "POINT", and the other isn't
AND point_location.locationtypeid = 4 
AND multipoint_location.locationtypeid != 4
) as subquery

JOIN location AS point_location 
ON point_location.locationid = point_locationid

JOIN location AS multipoint_location 
ON multipoint_location.locationid = multipoint_locationid

JOIN geographicreference as georef
ON point_location.locationid = georef.locationid

JOIN licence
ON licence.licenceid = subquery.licenceid

JOIN clientname USING (clientid)

-- Select only WGS84 LatLngs
WHERE georef.georeferencetypeid = 3
ORDER BY point_locationid
;
