sam - 7 months ago 12

PHP Question

How we can use OR condition in group by clause below is my sql query

`SELECT count(id) as num_rows,`

(3959 * acos ( cos ( radians(41.766908)) * cos( radians( lat ) ) * cos( radians( lon ) - radians(-81.1526976)) + sin ( radians(41.766908) ) * sin( radians( lat ) ))) AS distance

FROM (`items`)

WHERE `status` = 1

GROUP BY `distance`

HAVING `distance` <=50

In this query I have to add

`(GROUP BY `distance` HAVING `distance` <=50 OR `nationwide`=1)`

How we can execute above query ??

Below is my result - and I have to add OR condition in having by clause

1 2 22.4347083649522

1 2 46.8127635462102

8 2 10.0201103523007

13 1 11.888890536392

Answer

Probably it will help you

```
GROUP BY `distance`(HAVING `distance` <= 50 OR `nationwide` = 1);
```