我有两张桌子: -
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 = ?
获得我需要的结果的正确方法是什么?
答案 0 :(得分:2)
你在哪里有两次企业:
FROM users, businesses JOIN businesses
删除第一个,应该像以前一样:
FROM users JOIN businesses
答案 1 :(得分:1)
使用显式连接语法:
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
实际上不是必需的。
答案 2 :(得分:1)
有一个带有JOIN
语法的拼写错误,请尝试以下操作:
SELECT users.username, users.business_id, businesses.latitude, businesses.longitude
FROM users JOIN businesses ON users.business_id = businesses.business_id
WHERE service_type = ?