MYSQL: Simplify this Query for better performance

Posted by Treby on Stack Overflow See other posts from Stack Overflow or by Treby
Published on 2010-01-27T06:03:48Z Indexed on 2010/03/29 2:53 UTC
Read the original article Hit count: 325

Filed under:

How can i simplify this code. coz this uses subquerying

SELECT ub.id_product as c_pid,DATE(ub.datetime_prchs)AS datePurchased,cb.bookname, 
(SELECT GROUP_CONCAT(c.userid ORDER BY c.userid ASC SEPARATOR ', ')  FROM 
user_books ub 
INNER JOIN campus_bookinfo cb ON ub.id_product=cb.idx_campus_bookinfo 
LEFT JOIN customer c ON ub.id_customer=c.id_customer 
WHERE ub.id_product = c_pid 
)as buyer,
cb.iAmount FROM user_books ub 
INNER JOIN campus_bookinfo cb ON ub.id_product=cb.idx_campus_bookinfo 
LEFT JOIN customer c ON ub.id_customer=c.id_customer 
WHERE ub.id_customer = 29
GROUP BY bookname
ORDER BY ub.datetime_prchs

I need a better code for the same output.. Thanks in advance

© Stack Overflow or respective owner

Related posts about mysql