Laravel subquery whereIn -
i have problem query. want make subquery not return results.
here code :
$distance_representations = representation::select('id') ->where(db::raw('round(6371 * acos(cos(radians(45.0)) * cos(radians(latitude)) * cos(radians(longitude) - radians(2.7)) + sin(radians(45.0)) * sin(radians(latitude)))::numeric, 1) < 50')) ->limit(10) ->get(); $representations = representation::select('id', 'city', db::raw('round(6371 * acos(cos(radians(45.0)) * cos(radians(latitude)) * cos(radians(longitude) - radians(2.7)) + sin(radians(45.0)) * sin(radians(latitude)))::numeric, 1) < 50')) ->wherein('id', $distance_representations) ->get(); return view('search', array('representations' => $representations));
postgresql equivalent :
select id, city, round((6371 * acos(cos(radians(45.0)) * cos(radians(latitude)) * cos(radians(longitude) - radians(2.7)) + sin(radians(45.0)) * sin(radians(latitude))))::numeric, 1) distance representations id in ( select id representations round((6371 * acos(cos(radians(45.0)) * cos(radians(latitude)) * cos(radians(longitude) - radians(2.7)) + sin(radians(45.0)) * sin(radians(latitude))))::numeric, 1) < 50 limit 10 )
thank you
perhaps can try this
$distance_representations = representation::find('id') ->where(db::raw('round(6371 * acos(cos(radians(45.0)) * cos(radians(latitude)) * cos(radians(longitude) - radians(2.7)) + sin(radians(45.0)) * sin(radians(latitude)))::numeric, 1) < 50')) ->limit(10) ->get(); $representations = representation::all() ->where(db::raw('round(6371 * acos(cos(radians(45.0)) * cos(radians(latitude)) * cos(radians(longitude) - radians(2.7)) + sin(radians(45.0)) * sin(radians(latitude)))::numeric, 1) < 50')) ->wherein('id', $distance_representations.id) ->get();
hope you.
Comments
Post a Comment