Je to proto, že váš 1. SELECT
a 2. SELECT
mají různý počet sloupců, protože jste zavedli Distance
ve 2. SELECT
.
Zkuste tedy vytvořit Distance
v 1. dotazu null nebo 0 následovně.
SELECT * FROM
(
SELECT *, 0 as Distance
FROM user u
INNER JOIN employee e ON (u.empid = e.empid)
INNER JOIN awards a ON (u.empid = a.empid)
WHERE u.empid = 123
UNION
SELECT *, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) )+ sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance
FROM user u
INNER JOIN employee e ON (u.empid = e.empid)
INNER JOIN awards a ON (u.empid = a.empid)
HAVING distance < 25
ORDER BY distance
) a
ORDER BY timestamp DESC