mysql - SQL select query from comma separated string -


i have table with column location values

row1: sector a, sector b, sector c row 2: sector b, sector f, sector row 3: sector f 

no looking sql query search these rows comma separated string can search sector a, sector f in case row 1 ,row2, row 3 values should print sector a in row 1, row2 , sector f in row 3

i trying matches exact string ...

select id , name tb1 "+ "    charindex(','+cast(location      varchar(8000))+',',',"+loc+",') > 0 

and loc sector a,sector f

instead of having "location" column in main table comma separated values, should have second table. i'm going call first table inventory_item , assume here you're trying track locations inventory located (since didn't application does).

so add table called inventory_item_location columns:

id, inventory_item_id, location

you have 1 row per location in inventory_item_location table , inventory_item_id id of inventory_item table. query inventory_item_location table whatever sector you're looking for. , know items in locaiton.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -