java - Mysql query with In clause regex -
i have sql query this:
"select f.filterid filtename, f.id filtertext " +     "from filter f " +      "where group_id = '" + id +"' " +      "or groupids '%." + id + ".%' ";   and want pass list of ids query make performance better. don't know whether regex works in in clause. , tried below 1 not working , not sure use in case of regex.
"select f.filterid filtename, f.id filtertext filter f " +      "where group_id in ("+stringutils.join(ids, "','")+")" +      "or groupids in ("+stringutils.join(ids, "','")+")"";   thanks.
i recommend use query#setparameter achieve this, if using jpa can supply ids list in setparameter.
but current resolution may try below changes.
not sure if group_id column expects integer or string datatype, propose changes either of cases.
if expects string - missing starting " ' " change code below
if expects integer type - should not wrap comma separator " ' ", remove them below
"select f.filterid filtename, f.id filtertext filter f " + "where group_id in ("+stringutils.join(ids, ",")+")" + "or groupids in ("+"'"+stringutils.join(ids, "','")+"'"+")";   trying running query , see if desired resultset
Comments
Post a Comment