jwk811 Posted September 20, 2010 Share Posted September 20, 2010 $sql = "SELECT sum(tbl1.number) FROM tbl1, tbl2"; it only works if i have one table when i add the second it doesnt work. i just need the sum in one column from one table i just need other info from the other table too it wont work tho. im getting an entirely different number for the sum. Quote Link to comment Share on other sites More sharing options...
btherl Posted September 20, 2010 Share Posted September 20, 2010 Can you be more specific about what you want? There's many ways you can combine data from two tables. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted September 20, 2010 Author Share Posted September 20, 2010 i want to count one column but get other info from more than one table at the same time Quote Link to comment Share on other sites More sharing options...
mikosiko Posted September 20, 2010 Share Posted September 20, 2010 i want to count one column but get other info from more than one table at the same time here is a quick example for you to adjust to your tables... notice the way the tables are related using an INNER JOIN (in this case), and the GROUP BY clause allow you to give correct result for the aggregate function SUM SELECT P.productCode, P.productName, SUM(priceEach * quantityOrdered) total FROM orderdetails O INNER JOIN products P ON O.productCode = P.productCode GROUP by productCode ORDER BY total Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.