Attila Naghi
Attila Naghi

Reputation: 2686

Using LIKE operator in MySQL with comma s issue

This is my query:

SELECT
  store_id as `initial`,
  CONCAT(',', store_id, ',') AS store_id
FROM `mytable` AS `main_table`
WHERE (`store_id` LIKE '%,13,%');

These are the results without the where conditions:

enter image description here

When I executed my query , I got no results. Same for WHERE (store_idLIKE '%,3,%'); Is it some kind of rule or exception for the , and like operator ?

Thank you :)

Upvotes: 0

Views: 178

Answers (2)

Attila Naghi
Attila Naghi

Reputation: 2686

Using FIND_IN_SET fixed my problem. More Info: https://www.w3resource.com/mysql/string-functions/mysql-find_in_set-function.php .

Credit goes to @Jens

SELECT
  store_id as `store_id`,
FROM `ffm_nonpayment_actiontemplate` AS `main_table`
WHERE FIND_IN_SET('13', store_id);

Upvotes: 2

The problem is that field store_id in WHERE has initial value and not the value you calculate with CONCAT(',', store_id, ',') AS store_id If you want filter you can use HAVING keyword

Upvotes: 0

Related Questions