mysql - GROUP BY lname ORDER BY showing wrong results -


this query i've written, listing top 25 in sales competition, showing wrong results.

users aren't showing should pretty far on list. idea issue be?

select u.fname, u.lname, sum(p.point) points    comp_sale s, comp_product p, comp_user u  s.prod_id = p.product_id     , s.sale_id = u.wp_id   group lname   order points desc limit 25 

table comp_user:

user_id int(11) no  pri null    auto_increment fname   varchar(255)    no      null     lname   varchar(255)    no      null     storename   varchar(255)    no      null     city    varchar(255)    no      null     phone   varchar(255)    no      null     wp_id   int(11) no      null     type    varchar(255)    no      null     

table comp_sale

prod_id int(11) no      null     sale_id int(11) no      null     serial  varchar(255)    no      null     

table comp_product

product_id  int(11) no  pri null    auto_increment description varchar(255)    no      null     type    varchar(255)    no      null     cylinda_num int(11) no      null     eel_num int(11) no      null     point   int(11) no      null     

try using proper, ansi standard group by

select     u.fname, u.lname, sum(p.point) points      comp_sale s     join     comp_product p on s.prod_id = p.product_id      join     comp_user u on s.sale_id = u.wp_id group     u.fname, u.lname order      points desc  limit 25 

also, use explicit joins clarity


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -