Support the ongoing development of Laravel.io →
Database

here is my code

$products = DB::table('post_data') ->select('*') ->selectRaw('( 6371 * acos( cos( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin( radians(?) ) * sin( radians( latitude ) ) ) ) AS distance', [$latitude, $longitude, $latitude]) ->havingRaw("distance < ?", [$radius]) ->get();
echo "<pre>"; print_r($products); die;

it gives an error

Syntax error or access violation: 1463 Non-grouping field 'distance' is used in HAVING clause (SQL: select *, ( 6371 * acos( cos( radians(41.118491) ) * cos( radians( latitude ) )

  • cos( radians( longitude ) - radians(25.404509) ) + sin( radians(41.118491) ) * sin( radians( latitude ) ) ) ) AS distance from post_data having distance < 5)

if i'm not use having then it shows the results but this query runs in database

using laravel 5.4

please help me

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.