how to JOIN to a SUM/GROUP BY query

Results 1 to 3 of 3

Thread: how to JOIN to a SUM/GROUP BY query

  1. #1
    Join Date
    Dec 1969

    Default how to JOIN to a SUM/GROUP BY query

    If I run a standard group by/sum query: <BR><BR>SELECT product_ID,SUM(value) FROM Table<BR>GROUP BY product_ID<BR><BR>All well and good - gives me the list of product_IDs and the sums of the value fields.<BR><BR>However, I would like either to be able to get more data from the same table, or join to another table so I can use the product_ID index to get more info on that product. <BR><BR>But if I try <BR><BR>SELECT product_ID,another_field, SUM(value) FROM Table<BR>GROUP BY product_ID<BR><BR>I get an error message saying that "another_field" must be involved in the GROUP BY statement, and similarly, I can&#039;t seem to make any sort of join statement work to get data from another table. <BR><BR>I can&#039;t find any reference to this problem anywhere, but am sure it must be a common issue?<BR><BR>Can anyone help?

  2. #2
    Join Date
    Dec 1969

    Default RE: how to JOIN to a SUM/GROUP BY query

    SELECT Table.product_ID, Table2.another_field, SUM(Table.value) <BR>FROM Table Join Table2 on Table.product_ID = Table2.Product_ID<BR>GROUP BY Table.product_ID, table2.another_field<BR>

  3. #3
    Join Date
    Dec 1969

    Default Good old google...

    WK&#039;s specific answer is right, of course, but for a more general answer:<BR><BR><BR><BR>Tons of tutorials on this kind of stuff on the Web.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts