Mitul Lakhani Mitul Lakhani -5 years ago 162
SQL Question

select data mysql

i have in my table places named field. there are space separated values(there are problem to store csv value in one field). now i want to fire query like below. how i can do ??

select * from tablename where variablename in places

i did try this way but it shows syntax error.

select * from tablename where variablename in replace(places,' ',',')

### places ###

bank finance point_of_interest establishment

Answer Source

The best solution would be to normalise your data structure and do not have a single field storing multiple values.

You can make a query work without normalisation, but any solutions would be lot less optimal from a performance point of view.

  1. Use patter matching with like operator:

    ... where fieldname like '% searched_value %'

  2. Use the replace() function and combine it with find_in_set():

    ... where find_in_set('searched_value',replace(fieldname,' ',','))>0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download