MySQL error 1054: Unknown column in having clause

Bharanikumar picture Bharanikumar · Nov 1, 2010 · Viewed 11.3k times · Source

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

Answer

codaddict picture codaddict · Nov 1, 2010

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

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