我需要將這兩個查詢放在一個查詢中的幫助。例如,我想在數據庫中搜索與$ sql的半徑和$ sql2的半徑相匹配的旅程,並獲得與兩者匹配的結果。如何加入這些查詢
$sql = "SELECT adpastrip_id,
(3959 * acos(cos(radians($lat)) * cos(radians(lat1)) * cos(radians(long1) - radians($lng)) + sin(radians($lat)) * sin(radians(lat1)))) AS distance
FROM addgoodstrip
HAVING distance < 10
ORDER BY distance
LIMIT 0 , 20";
$sql2 = "SELECT adpastrip_id,
(3959 * acos(cos(radians($lat2)) * cos(radians(lat2)) * cos(radians(long2) - radians($lng2)) + sin(radians($lat2)) * sin(radians(lat2)))) AS distance
FROM addgoodstrip
HAVING distance < 10
ORDER BY distance
LIMIT 0 , 20 ";
聯合查詢不會返回匹配兩個距離準則,它將返回那些符合至少一個,但不一定是另一種。 – Shadow
@Shadow union會合並2個查詢的結果。我希望這是OP所需要的 –