mysql - Distinct not working properly -
i've wrote query distinct
still duplicate records returned.
select distinct `cuisine_types`.`id`, `cuisine_types`.`name`, `cuisine_types`.`image`, ( select group_concat(`tagname` separator ', ') `cuisine_tags` `cuisine_type` = `cuisine_types`.`id` ) tags, ( 3959 * acos( cos( radians(" . $dlat . ") ) * cos( radians( gps_lat ) ) * cos( radians( gps_lon ) - radians(" . $dlon . ") ) + sin( radians(" . $dlat . ") ) * sin( radians( gps_lat ) ) ) ) distance `company` left bring together `cuisine_types` on `company`.`cuisine_type_id` = `cuisine_types`.`id` having distance < " .$dmiles
when seek using group by
function query isn't working properly. when utilize group by
place above having
:
group `cuisine_types`.`name`
examples:
when utilize these values:
$dlat = '52.779716'; $dlon = '21.84803'; $ikm = '30';
it returns:
id = 1 name = snackbar image = tags = patat, snacks distance = 17.4713944772963
when utilize $ikm
3000 returns row well:
id = 1 name = snackbar image = tags = patat, snacks distance = 722.407714147792
so 2 records. when utilize groupby , $ikm
= 30; returns nothing. value of 3000 returns 1 row. have 1 record distance of 17 miles thats below 30.
this should prepare problem, issue distance calculation blocked group by
function. putting equation in having
itself, problem seemed fixed. sorry can't explain in more detail.
select `cuisine_types`.`name`, `cuisine_types`.`id`, `cuisine_types`.`image` `c`.`gps_lat` lat, `c`.`gps_lon` lon, (select group_concat(`tagname` separator ', ') `cuisine_tags` `cuisine_type`=`cuisine_types`.`id`) tags `company` c left bring together `cuisine_types` on c.`cuisine_type_id` = `cuisine_types`.`id` grouping `cuisine_types`.`name` having ( 3959 * acos( cos( radians(52.779716) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(21.84803) ) + sin( radians(52.779716) ) * sin( radians( lat ) ) ) ) < 2000;
mysql sql distinct having
No comments:
Post a Comment