0

Hey guys I'm getting a syntax error on my CONCATS for some reason, this is very weird since its pretty much a copy/paste from another one of my queries using CONCATS that works flawlessly?

Here's the bad query

SELECT 
    brand, 
    case_count AS case, 
    variety, 
    style, 
    grower_lot AS lot, 
    pack_date AS date, 
    CONCAT(berry_size1, "-", berry_size2, "/", berry_size3, "-", berry_size4) AS size, 
    CONCAT(color1, "-", color2) AS color, 
    CONCAT(stem1, "-", stem2, "-", stem3) AS stem_cndt, 
    CONCAT(bunch_count1, "-", bunch_count2, "-", bunch_count3) AS bnch_cnt, 
    CONCAT(shatter1, "-", shatter2) AS shatter, 
    CONCAT(splits1, "-", splits2) AS split, 
    CONCAT(decay_count1, "-", decay_count2) AS decay, 
    CONCAT(wet_sticky1, "-", wet_sticky2) AS wet_sticky, 
    overall_quality AS quality, 
    CONCAT(sugar_brix1, "-", sugar_brix2) brix, 
    overall_condition AS condition, 
    rating, 
    inspector AS insp, 
    comments 
FROM `lot`

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'case, variety, style, grower_lot AS lot, pack_date AS date, ' at line 3

And here's one that seems to work

SELECT
        shipper, 
        po, 
        commodity as comm, 
        count, 
        size, 
        label, 
        variety, 
        pack_date AS date, 
        grower_lot AS lot, 
        CONCAT(color1, "-", color2) AS color, 
        CONCAT(sizing1, "-", sizing2, " / ", "sizing3", "-", sizing4 ) AS size, 
        CONCAT(firmness1, "-", firmness2) AS firmness, 
        CONCAT(scars_count1, "-", scars_count2) AS scars, 
        CONCAT(bruise_count2, "-", bruise_count2) AS bruise, 
        CONCAT(decay_count1, "-", decay_count2) AS decay_cnt, 
        CONCAT(sugar_brix1, "-", sugar_brix2) brix, 
        rating, 
        inspector AS insp, 
        comments
FROM `berries`
1
  • Please paste the error message. Commented Mar 1, 2012 at 17:57

2 Answers 2

4

Not an issue with CONCAT per se, but case is a reserved word in MySQL, and needs to be backtick-escaped.

Sign up to request clarification or add additional context in comments.

3 Comments

After changing case to case_cnt I get the error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'condition, rating, inspector AS insp, comments FROM lot LIMIT 0, ' at line 18
Unfortunately, condition is another reserved word. @Mchl's response links to the full list of reserved words.
Yep that was it, just seem to be using all the reserved words today =P
1

case is MySQL's reserved word. You need to put it within backticks, if you want to use it as column alias.

Full list of reserved words available here: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.