Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2007
    Posts
    20

    Unanswered: Group by problems

    Code:
            Select  OD.OrderNum,
                     SUM(OD.OrderQty) As Qty,
                     P.PartNum,
                     OH.CustNum
            From    OrderDtl OD, Part P, OrderHead OH
            Where  P.PartNum = '12345' 
            And     P.PartNum = OD.PartNum
            And     OD.OrderNum = OH.OrderNum
            Group by OrderNum, PartNum, CustNum
    Error returned is: Non-group-by expression in select clause

    Everything is fine until I join in the OrderHead table

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    1. better to use ANSI join syntax.
    2. add the table aliases to the group by clause:

    Group by OD.OrderNum, P.PartNum, OH.CustNum

  3. #3
    Join Date
    Feb 2007
    Posts
    20
    THANKS!!! That was frustrating.

    I guess it let me join on the first two tables without specifying the alias because there were no ambiguous columns?? (just a guess) But from now on I'll ALWAYS specifiy the alias.

    As I guess that is the proper way of writing the query?

  4. #4
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    Quote Originally Posted by landrun
    I guess it let me join on the first two tables without specifying the alias because there were no ambiguous columns??
    yes

    Quote Originally Posted by landrun
    As I guess that is the proper way of writing the query?
    yes it is. now use the ANSI join syntax and you'll be all set.

Posting Permissions

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