mysql count, distinct, join? COnfusion
Posted
by calum
on Stack Overflow
See other posts from Stack Overflow
or by calum
Published on 2010-04-18T15:15:52Z
Indexed on
2010/04/18
15:23 UTC
Read the original article
Hit count: 416
hello i have 2 tables:
tblItems
ID | orderID | productID
1 1 2
2 1 2
3 2 1
4 3 2
tblProducts
productID | productName
1 ABC
2 DEF
im attempting to find the most popular Product based on whats in "tblItems", and display the product Name and the number of times it appears in the tblItems table.
i can get mysql to count up the total like:
$sql="SELECT COUNT(productID) AS CountProductID FROM tblItems";
but i can't figure out how to join the products table on..if i try LEFT JOIN the query goes horribly wrong
hopefully thats not too confusing..thankss
© Stack Overflow or respective owner