0

I have a simple MySQL statement that keeps showing an error.

type is an column in table ps_product_custom_statistics_weekly and i would like to select only the value from type where it has an value of all.

SELECT `cat`.`brand_name`
FROM `ps_product_brand` AS `cat`
INNER JOIN `ps_product_custom_statistics_weekly` AS `cat_p` 
ON `cat_p`.`id_product` = `cat`.`id_product`
WHERE `cat_p`.`type` LIKE `%all%`
AND `cat_p`.`rank` <= 16;

Error msg :

#1054 - Unknown column '%all%' in 'where clause'

(i dont understand why it tells me this, im using cat_p.type to select column and LIKE %all% to get string from that column, please help)

Table:

ps_product_custom_statistics_weekly

  product_id        type            rank
+-------------+--------------+------------------+
|      1      |    weekly    |       20         |
+-------------+--------------+------------------+
|      2      |      all     |       10         |
+-------------+--------------+------------------+

Thanks

2
  • Use the correct quote characters, backtick (`) for identifiers, single quotes (') for string literals. Commented Jan 16, 2018 at 9:41
  • please tag correctly, it should be only MySQL, not sql server also Commented Jan 16, 2018 at 9:41

3 Answers 3

1

The problem is that you are using backticks instead of single quotes. Use it like this:

WHERE `cat_p`.`type` LIKE '%all%'
Sign up to request clarification or add additional context in comments.

Comments

1

You should give quotes to like condition like below,

SELECT `cat`.`brand_name`
FROM `ps_product_brand` AS `cat`
INNER JOIN `ps_product_custom_statistics_weekly` AS `cat_p` 
ON `cat_p`.`id_product` = `cat`.`id_product`
WHERE `cat_p`.`type` LIKE '%all%'//Change quotes
AND `cat_p`.`rank` <= 16;

Backquotes ` should not work for string manipulation in mysql query

Comments

0

Solution must be

SELECT `cat`.`brand_name`
FROM `ps_product_brand` AS `cat`
INNER JOIN `ps_product_custom_statistics_weekly` AS `cat_p` 
ON `cat_p`.`id_product` = `cat`.`id_product`
WHERE `cat_p`.`type` LIKE '%all%'
AND `cat_p`.`rank` <= 16;

As Like value must be in '' not in ``

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.