Itu karena SELECT
pertama Anda dan SELECT
ke-2 memiliki jumlah kolom yang bervariasi, sejak Anda memperkenalkan Distance
di SELECT
ke-2 .
Jadi coba buat Distance
dalam kueri pertama null atau 0 sebagai berikut.
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