Bharanikumar
Bharanikumar

Reputation: 25733

MySQL error 1054: Unknown column in having clause

Query:

  SELECT SUM(ProductCost) 
    FROM `tblBasket` 
GROUP BY ProductCode
  HAVING BasketSessionID = '3429782d79c68834ea698bb4116eef5e'

Showing Error Like:

1054 - Unknown column 'BasketSessionID' in 'having clause'

What is the mistake in my query?

alt text

Upvotes: 4

Views: 12550

Answers (3)

dotariel
dotariel

Reputation: 1604

HAVING filters out aggregates. You should try GROUP BY.

Upvotes: 2

Jon Snyder
Jon Snyder

Reputation: 2009

I think you want to use a where clause not having.

Upvotes: 2

codaddict
codaddict

Reputation: 455020

Try using a where clause in place of the having clause:

SELECT SUM(ProductCost) 
FROM `tblBasket` 
WHERE BasketSessionID ='3429782d79c68834ea698bb4116eef5e'
GROUP BY ProductCode

Upvotes: 12

Related Questions