Results 1 to 3 of 3

Thread: Error When I Use an Added Value in a Conditional in Same Query

Hybrid View

  1. #1
    Join Date
    Jan 2003

    Wink Error When I Use an Added Value in a Conditional in Same Query

    When I run the following query:
    SELECT b.*, g.genreName,
    (b.boxSets1 + b.boxSets2 + b.boxSets3 + b.boxSets4 + b.boxSets5) AS boxTotalSets,
    (b.boxTime1 + b.boxTime2 + b.boxTime3 + b.boxTime4 + b.boxTime5) AS boxTotalTime,
    (b.boxMusicOnly + b.boxDrillOnly) AS boxTotalPrice
    FROM box5 AS b
    LEFT JOIN genres AS g ON g.genreID=b.boxGenre
    WHERE b.boxEnabled = 'Yes' AND b.boxMusicGrade=3
    AND b.boxGenre=7 AND (boxTotalSets > 40 AND boxTotalSets <= 45)
    AND b.boxDrillGrade=3 AND (boxTotalTime > 420 AND boxTotalTime <= 450)
    AND b.boxDesigner=1 AND (boxTotalPrice > 3200 AND boxTotalPrice <= 3400)
    ORDER BY b.boxTitle
    I get this error:
    #1054 - Unknown column 'boxTotalSets' in 'where clause'
    Is it not possible for me to use boxTotalSets, boxTotalTime, and boxTotalMusic in conditionals in the same MySQL query? If not -- how can this be done? Thank you for any help you can provide.

  2. #2
    Join Date
    Dec 2002
    St. Louis, MO, USA
    Are you sure that all of the column values that you're trying to sum are populated with integers or floats?

    Take a look at the following:

    According to the above link, if one of the values is NULL, then the result is NULL. Try ISNULL(column,0).
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long


  3. #3
    Join Date
    Jan 2003
    I was able to get it working. I needed to use 'HAVING'.

    Thank for responding.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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