0

I have a field in my Database table colled interet, it has a json array like you see in this picture. enter image description here

I want to check if one values or two is IN this fields using Mysql query. I was trying to do this query:

SELECT * FROM customers c WHERE c.interet IN ('Voyage','Technologie','Mode')

But I got nothing

Malki Mohamed
  • 1,578
  • 2
  • 23
  • 40
  • 2
    that is not a json_array – e4c5 Jan 03 '17 at 12:01
  • 1
    it's not json. looking string or text type data – Alive to die - Anant Jan 03 '17 at 12:03
  • 1
    What you have in your table is not JSON but simply comma separated values in a column. Which you should not be saving in a column. Please see http://stackoverflow.com/a/41215681/267540 and http://stackoverflow.com/a/41305027/267540 – e4c5 Jan 03 '17 at 12:07
  • aaah ok so if I make it json array will be worked ? – Malki Mohamed Jan 03 '17 at 12:08
  • 1
    not json array but can use like : where c.interet like '%Voyage%' or c.interet like '%Technologie%' or c.interet like '%Mode%' group by id – san san Jan 03 '17 at 12:10
  • JSON will only make things marginally better. Please google for database normalization and read the two QAs in my previous comment – e4c5 Jan 03 '17 at 12:20

2 Answers2

1

Since it is not json USE like operator

    SELECT * FROM customers c WHERE 
    c.interet LIKE '% Voyage %' OR 
    c.interet LIKE '% Technologie %' OR 
    c.interet LIKE '% Mode %' 
Sanooj T
  • 1,317
  • 1
  • 14
  • 25
0

The format above is not json it is a varchar. update your question and post your full sql query

Afaf
  • 654
  • 1
  • 5
  • 17