mysql - Selecting A Row Based On One Value In A Multi-Value Array Using IN Clause -


i have column in database values stored comma separated array; let's sample entry in database be: 1, 5, 8, 15

i trying use data in select statement allow user select entry in database array contains value select (the values tied look-up table join in actual application, user not see integers).

my simplified select statement essentially:

$arrayvalue = "1";     $query = "select * table tablearray in ($arrayvalue)"; 

for example put in 1 array value 1 searching for; in actuality variable populated post form input user has control of.

'tablearray' name of column containing comma separated array said contain 1, 5, 8, 15 example (though varies in reality).

this statement in clause works fine me right data in table column has 1 value, or multiple values in array when select first value in array, not return second value if select i.e. if set $arrayvalue 1 works, 5 not return row in results.

i not need select multiple values array @ time, want work select 1 value table column regardless of integer falls in array. suspect missing simple here, if can help.

select * table tablearray concat('%',$arrayvalue,'%'); 

to avoid '5' finding '15',etc... issue identified in comment below, use following pattern, assumes values seperated comma no spaces before or after comma.

where   tablearray concat('%,',$arrayvalue,',%') or      tablearray concat($arrayvalue,',%'); or      tablearray concat('%,',$arrayvalue) 

btw, hack around fact these attributes should normalized rows.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -