Questions tagged [find-in-set]

MySQL FIND_IN_SET() returns the position of a string if it is present (as a substring) within a list of strings.

MySQL FIND_IN_SET(str, strlist) is a string function that returns the index position of the search string str inside the string list strlist. The string list itself is a string containing substrings separated by ‘,’ (comma) character.

This function returns 0 when search string does not exist in the string list and returns NULL if either of the arguments is NULL.

Syntax

FIND_IN_SET(search_string, string_list)

Arguments

  • search_string: a string which is to be looked for in following list of arguments.
  • string_list: list of strings to be searched if they contain the search string.

Example

The following MySQL statement finds the search string ‘ank’ at 2nd place within the string list. So it returns 2.

Code

SELECT FIND_IN_SET('ank','b,ank,of,monk');

Output

FIND_IN_SET('ank','b,ank,of,monk')
2
149 questions
0
votes
3 answers

MySQL select from multiple tables with multiple where clauses and find_in_set

I'm having an issue trying to avoid partial duplicate results with a MySQL query. I admit I'm really new at MySQL but I have learned from research on SO that the schema I'm about to lay out for you below could definitely be done a better way (the…
Dan
  • 121
  • 2
  • 10
0
votes
2 answers

Get Values not in the second table using find_in_set

I have two tables and i need to get list of all store_ids that are not in the other table BusinessUnit Table User Table StoreId(varchar) StoreId(varchar) 1 1,2 2 3,4 3 1,5 4 …
Learner2011
  • 287
  • 2
  • 6
  • 25
0
votes
3 answers

MySQL : check if a "value" is in one field but is not in another one?

I have a table like this: id | value1 | value2 ------------------------- 1 | a,b,c,d | a,d,e,f ------------------------- 2 | d,e,f,a | ------------------------- 3 | a,x,y,z | d,e,f How can I get all rows that have "a" in [value1] but…
Nấm Lùn
  • 1,277
  • 6
  • 28
  • 48
0
votes
1 answer

MYSQL query Optimization with FIND_IN_SET and Multiple Table JOINS

Below query takes about 6-7 sec . I want the result in less than 1 sec. What Shall i DO. Will indexing catsid colum used in find_in_set help ? **EXPLAIN SELECT** sp_events.id,sp_events.id as speventId, event.id as eventId,event.cityid as…
Vivek Tankaria
  • 1,301
  • 2
  • 15
  • 35
0
votes
0 answers

I want to rewrite my MySQL query so that FIND_IN_SET doesn't do a full table scan unless necessary

I want to rewrite my MySQL query so that the last table join doesn't do a full table scan unless necessary. table1.csv is a varchar field containing comma separated IDs that relate to table2's join_id column. I only want to call FIND_IN_SET which…
PHPguru
  • 491
  • 4
  • 5
0
votes
1 answer

Mysql: Using GROUP_CONCAT & FIND_IN_SET in where without having or subquery

Hi I have a simple example query below that is not what I am using in reality as it is far too complex to explain here. Basically this query is being used in a search in a web application. Due to the amount of data that this query could pull out I…
Dan Mason
  • 2,177
  • 1
  • 16
  • 38
0
votes
2 answers

find_in_set and regex in a select query

Is there any way to check for a regex expression in a comma separated values column? I have a column named storeId with the following values EMP_0345,00345,OPS and I need to get only the storeid with no alpha numeric characters in it. I am able to…
Learner2011
  • 287
  • 2
  • 6
  • 25
0
votes
1 answer

MySQL complicated ORDER BY issue

Due to changing requirements I've revisited an interface I created a couple of months ago. More features, more data. I received help with the tricky ordering requirements of the data over here. But requirements have changed, or to be more accurate,…
Matt
  • 1,377
  • 2
  • 13
  • 26
0
votes
2 answers

FIND_IN_SET with comma seperated values for sorting condition

I am using find_in_set for fetching data using below query and it works correctly. SELECT * FROM A WHERE FIND_IN_SET( column1, ( SELECT column1 FROM B WHERE id = 21) ); Here this query SELECT column1 FROM B WHERE id = 21 gives result like…
Deval Shah
  • 1,094
  • 8
  • 22
0
votes
2 answers

Mysql group_concat with distinct and where gives strange results

I have the following query which works fine (see below). But when I add a condition, for example AND (specialtyName = '...') the main results are fine, but the GROUP_CONCAT only shows the results that match the condition. Can anyone please help me…
Fred
  • 5
  • 4
0
votes
1 answer

SQL Select Query With FIND_IN_SET Or Any things else to find comma separated values in a column with comma separeted values

I have one column having comma separated values: id Column_name == ========== 1 value1,value2,value3,value5 2 value2,value3,value4 3 value1,value3,value5 4 value1,value2,value4,value5 Now, I want a query that get all records having value2 OR…
0
votes
4 answers

compare 2 strings seprate by comma in sql query

I have a table with fields like this category -------------- 20,14,13,16,19 And i have this string: 20,16,9,5 I want to find products that have this categories in mysql query. someone have an idea?
oded
  • 155
  • 1
  • 4
  • 16
0
votes
1 answer

get the position of row split by comma

I have a row in my sql table that look like this I would like to run query with find_in_set like this: list ------------ 1,2,5,33,3,4 SELECT * FROM mytable WHERE FIND_IN_SET( id, list ) and get the position of the result in a new field
oded
  • 155
  • 1
  • 4
  • 16
0
votes
1 answer

mysql | Request from empty column and FIND_IN_SET

I have a table: id name position status 1 A 1,2 1 2 B 1 1 3 C 1 4 D 2 1 Where: position column is a text field; My request is here: SELECT `id` FROM `table` WHERE…
XTRUST.ORG
  • 3,280
  • 4
  • 34
  • 60
0
votes
3 answers

query on FIND_IN_SET

The following query SELECT ASSOCIATED_RISK FROM PROJECT_ISSUES WHERE FIND_IN_SET('98',ASSOCIATED_RISK); returns output as 96,98 90,98 but if I use SELECT ASSOCIATED_RISK FROM PROJECT_ISSUES WHERE FIND_IN_SET('96,98',ASSOCIATED_RISK); it…
eshaa
  • 386
  • 2
  • 7
  • 26
1 2 3
9
10