php - How to group by in mysql without showing duplicates? -
i building search page babysitter listing , users can filter results based on wage, distance , rating. works fine, getting 3 or 4 results when there 2 people or 1 people , cannot figure out.
here query:
select `users`.`id` `user_id`, `user_wage_preferences`.`one_child` `wage`, `user_contact_informations`.`lat`, `user_contact_informations`.`lng`, `user_reviews`.`rating`, sum(user_reviews.recommended) recommended, ( 6371 * acos(cos(radians(59.448355500000005)) * cos(radians(lat)) * cos( radians(lng) - radians(24.7406023)) + sin(radians(59.448355500000005)) * sin( radians(lat))) ) distance `users` left join `user_reviews` on `users`.`id` = `user_reviews`.`nanny_id` inner join `user_wage_preferences` on `users`.`id` = `user_wage_preferences`.`user_id` inner join `user_contact_informations` on `users`.`id` = `user_contact_informations`.`user_id` `users`.`role` = ? , `users`.`account_status` = ? , `users`.`id` in ( ?, ? ) group `user_id`, `user_contact_informations`.`lat`, `user_contact_informations`.`lng`, `user_reviews`.`rating`, `user_wage_preferences`.`one_child` having `recommended` > ? order `recommended` desc
on json response see this:
[ { "user_id":1, "wage":"6", "lat":59.44, "lng":24.74, "rating":5, "recommended":"1", "distance":0.92971285651468 }, { "user_id":4, "wage":"4", "lat":59.46, "lng":24.83, "rating":5, "recommended":"1", "distance":5.2153552636895 }, { "user_id":1, "wage":"6", "lat":59.44, "lng":24.74, "rating":4, "recommended":"0", "distance":0.92971285651468 }, { "user_id":4, "wage":"4", "lat":59.46, "lng":24.83, "rating":1, "recommended":"1", "distance":5.2153552636895 } ]
as can see user_id 1
, user_id 4
twice. , cannot figure out how remove duplicates or group user id
.
what doing wrong here? how can show users once? using laravel framework.
you have different rating in result.
i can see rating 4, 5 user1. if remove rating 1 record.
also can use group contact multiple ratings comma separated string - group_concat(rating order rating asc)
wiki
Comments
Post a Comment