我有两个桌子:

users (username, business_id, etc.)

businesses (business_id, service_type, latitude, longitude, etc.)

我有以下查询,可以正常工作:

SELECT username, users.business_id FROM users JOIN businesses
ON users.business_id = businesses.business_id WHERE service_type = ?


现在,我想在结果中也有“企业”表中的“纬度”和“经度”列。我怎样才能做到这一点?

我尝试执行以下操作,但出现错误:

SELECT username, users.business_id, businesses.latitude, businesses.longitude
FROM users, businesses JOIN businesses
ON users.business_id = businesses.business_id WHERE service_type = ?


什么是获得所需结果的正确方法?

最佳答案

使用显式联接语法:

SELECT username, users.business_id,
       businesses.latitude, businesses.longitude
FROM users
JOIN businesses
   ON users.business_id = businesses.business_id
WHERE service_type = ?


您正在将隐式与显式语法混合在一起。因此,实际上没有必要在, businesses子句中使用FROM

09-10 09:46