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
1
vote
1 answer

MySQL FIND_IN_SET function with special character not working

I have a stored procedure: CREATE PROCEDURE MyDB.`tag_quicktrend`( IN taglist TEXT ) BEGIN SELECT * FROM taginfo WHERE FIND_IN_SET(tagname,taglist); END; When I call SP: call sp_chart_band_tag_quicktrend('YH05_한글') it return correct…
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
1
vote
1 answer

Find comma separated value in a column by using comma separated list

I have a a column item_id_list with comma separated id such as this: I can search them by using FIND_IN_SET() such as this: SELECT * FROM task_detail WHERE FIND_IN_SET('21', item_id_list) but I need to check whether multiple id did exist in the…
sg552
  • 1,521
  • 6
  • 32
  • 59
1
vote
2 answers

MySQL, returning row using find_in_set is not working as expected

I'm trying to run the following MySQL command: SELECT ID, intervention_post_title, linked_article FROM wp_cpt_combined WHERE FIND_IN_SET (72, habitat_type) Inside my database the column habitat_type (as this is a multiselect field) stores the…
user142553
  • 55
  • 1
  • 7
1
vote
2 answers

FIND_IN_SET in cakephp not working

I have a table in which category ids are stored in the DB as comma separated values, so I need to search another array in this comma separated values. Need to search $required_ids_array in Posts.category_ids $required_ids_array = Array ( [0]…
Cliff_Cleet
  • 201
  • 1
  • 3
  • 14
1
vote
1 answer

MySQL Exclude Over Include in FIND_IN_SET()

For example, I have a table like this: ---------------------------------------------------------------------------- | id | title | tags …
James Arnold
  • 698
  • 3
  • 9
  • 22
1
vote
2 answers

Update records in one table for register present in another table, in a comma separated field

I have two tables: FirstTable: code store sent 1000002 Store1 0 1000002 Store2 0 1000002 Store3 0 SecondTable: code stores 1000002 Store1,Store3 What I want to do is to update FirstTable.sent for an specific code, only for the records…
rain_
  • 734
  • 1
  • 13
  • 24
1
vote
3 answers

difference between where_in and find_in_set

I am working on a join query in which I have to get the data from a column which contain the comma separated values.like allowed_activity contain 1,2,3,4,5,6 this the activity_id which is allowed. So In the query, I am checking that current activity…
always-a-learner
  • 3,671
  • 10
  • 41
  • 81
1
vote
0 answers

How to join tables in Hive using find_in_set

Table A contains a column id(string) Table B contains a column ids(string),like "id1,id2,id3" to join A and B, I want A.id can be found in B.ids: select count(1) from (select id from A) as t1 join (select ids from B) as t2 on find_in_set(t1.id,…
YuShi
  • 11
  • 2
1
vote
1 answer

SQL/PHP find_in_set

I'm trying to pull results where 1 row from tableA (profiles.category) matches 1 row from tableB (projects.categorysecond) however I'm not getting results. *IMPORTANT projects.categorysecond will vary between having only 1 category to several…
SiREKT
  • 37
  • 6
1
vote
0 answers

Mysql replace list of columns from another table

this is an example, it's similar to my project i have two tables no link between Table1 and Table2. TABLE1 id! LIST(string)! FNAME! lNAME ! postalcode! country! 1! (FNAME lNAME, postalCode) ! fname1! lname1! 02116! …
user7449991
1
vote
1 answer

Fetch row from table which matches a value in one column and presence of sub-string in comma separated string in other column

Question How to find rows which matches value in one column ( using = operator) and other column should have a substring (using find_in_set or other substring match). Scenario : I have three mysql tables: 1. Figures: It have details of figures like…
Sarge
  • 178
  • 1
  • 1
  • 8
1
vote
2 answers

Order by Field or Find_in_set without IN()

I'm building a MySQL query for a search function, now I want to order the outcome in a certain way using an array of ID's. I've been able to do this by using a piece of MySQL similar to this: SELECT id, name FROM mytable WHERE id IN (77, 3, 123, 1)…
Lennart
  • 639
  • 4
  • 14
1
vote
0 answers

Get each category id from column table with separate comma to show value

I realy need help to fix this code. Actualy I want get gcm_id from table where the user selects several category from table category. An example of what I want main point is gcm_id data "gcm_id will show if user select category A,B,C" etc.. How do…
1
vote
1 answer

Query to select Id if in result of another query

I'm trying to select Ids from a table if they were found by a query on another table (my final goal is to delete, from second table, rows with ids in the first query). Here are my attempts: SELECT @MyList:=GROUP_CONCAT(Id SEPARATOR ', ') AS…
genespos
  • 3,211
  • 6
  • 38
  • 70
1
vote
1 answer

MYSQL query to count descendants of items by finding its id in a comma separated string

My MYSQL database uses a tree-like system where each item can have an arbitrary number of descendants. Each item has a regular INT 'parent' column containing its parent as well as a VARCHAR 'parents' column which consists of a comma-separated…
IndigoFenix
  • 291
  • 2
  • 20
1 2
3
9 10