mysql - How to handle ambiguous field in my SQL -
select tb.id, latitude, longitude, 111151.29341326 * sqrt( pow( -6 - `latitude` , 2 ) + pow( 106 - `longitude` , 2 ) * cos( -6 * 0.017453292519943 ) * cos( `latitude` * 0.017453292519943 ) ) distance `tablebusiness` tb join `tablecity` tc on tb.city = tc.city join `businessestag` bc on bc.businessid = tb.id join `businessesdistricts` bd on bd.businessid = tb.id join `tabledistrict` td on td.id = bd.district ( `title` '%restaurant%' or `street` '%restaurant%' or tb.city '%restaurant%' or bc.tag '%restaurant%' or td.district '%restaurant%' ) , ( - 6.0917668133836 < `latitude` , `latitude` < - 5.9082331866164 , 105.90823318662 < `longitude` , `longitude` < 106.09176681338 ) order distance limit 0, 100 this mysql went through
then want based on building too.
so did, suggested do
select tb.id, latitude, longitude, 111151.29341326 * sqrt(pow(-6 - `tb.latitude`, 2) + pow(106 - `tb.longitude`, 2) * cos(-6 * 0.017453292519943) * cos(`tb.latitude` * 0.017453292519943)) distance `tablebusiness` tb join `tablecity` tc on tb.city = tc.city join `businessestag` bc on bc.businessid = tb.id join `businessesdistricts` bd on bd.businessid = tb.id join `tabledistrict` td on td.id = bd.district left join `tablebusiness` tbuilding on tbuilding.id = tb.building (`title` '%restaurant%' or `street` '%restaurant%' or tb.city '%restaurant%' or bc.tag '%restaurant%' or td.district '%restaurant%' or tbuilding.title '%restaurant%') , (-6.0917668133836 < `tb.latitude` , `tb.latitude` < -5.9082331866164 , 105.90823318662 < `tb.longitude` , `tb.longitude` < 106.09176681338) order distance limit 0, 100 then got message latitude fields ambiguous.
what should do?
i did obvious adding tb. before latitude
explain select tb.id, tb.latitude, tb.longitude, 111151.29341326 * sqrt(pow(-6 - `tb.latitude`, 2) + pow(106 - `tb.longitude`, 2) * cos(-6 * 0.017453292519943) * cos(`tb.latitude` * 0.017453292519943)) distance `tablebusiness` tb join `tablecity` tc on tb.city = tc.city join `businessestag` bc on bc.businessid = tb.id join `businessesdistricts` bd on bd.businessid = tb.id join `tabledistrict` td on td.id = bd.district left join `tablebusiness` tbuilding on tbuilding.id = tb.building (`title` '%restaurant%' or `street` '%restaurant%' or tb.city '%restaurant%' or bc.tag '%restaurant%' or td.district '%restaurant%' or tbuilding.title '%restaurant%') , (-6.0917668133836 < `tb.latitude` , `tb.latitude` < -5.9082331866164 , 105.90823318662 < `tb.longitude` , `tb.longitude` < 106.09176681338) order distance limit 0, 100 and error #1054 - unknown column 'tb.latitude' in 'field list'
i suppose need prepend latitude referring tb alias
select tb.id, tb.latitude, ... it may happen, longitude ambiguous, i'd suggest prepending appropriate alias well.
upd.:
i additionally suggest remove quotes surrounding tb.latitude , tb.latitude causing "unknown column" error.
Comments
Post a Comment